Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Defining Pages on Form


When we design a Form we will limit the placement of form controls within the visible area on the screen.  A Form’s dimension is 22 x 22 inches.  So you have plenty of real estate to work with, if you know how to use it.  Placing controls on this big surface is not difficult, but if not in a well organized manner then users may not find it convenient to use it.

Page Usage Plan.

Let us make a plan to create a four page layout on a sample Form to try them out.  If the visible area of the form on the screen is approximately ten inches wide then we can define two pages across the screen of about ten inches each.  We can define another two pages, after leaving about 5 inches from the top of the form, below the first two logical pages.  The Form Pages layout diagram is given below for a quick reference of our project.

There are four logical Page areas planned as shown above.  But, on physical terms there are only two pages, the top first page area with two segments across, first segment starting at co-ordinates at 0,0 (0 inch horizontal starting point at left and 0 inch vertical starting point at top or top left corner).  The second segment of the first page (or second logical page) starts at 10 inch location from left of the form and 0 inch vertical position.

Size of a logical page is about 10 inch wide and 5 inch high. But, we need to specify only the left top corner coordinates of each Page, in our Macro for transferring control from one page to the other.  The second logical page area (top right) is starting at 10 inch position from left of the form and 0 inch top position vertically (10,0).  The Command Buttons shown at the bottom right corner of the logical pages will run a macro to jump from one page to the other.

The Page-Break Control.

The dotted line at the left side at 5 inch position is a page-break control, inserted from the Toolbox, to define the second physical page area. The form area below the page-break control is the second physical page area.  This also divided into two logical pages like we did on the first page.  The first logical page (or the third logical page on the form) of the second physical page starts at 0 inch from left and at 0 inch position on the second page vertically (i.e. 5 inch down from top of the form).  Second logical page on the second physical page (or the fourth logical page on the form) starts at 10 inch position from left of the form and 0 inch position of the second physical page.

Ten inch width and five inch height logical page values are arbitrarily selected, you may change them if you find the pages are overlapping on your screen.  Following the same rules you can define more pages on the form, if you need them.

The Page Navigation Plan.

A Click on the first Command Button the control will jump to the second page at right top corner, the Command Button there will send the control to the left bottom page and pushing the command button there will pass the control to the right bottom corner page.  The right bottom corner command button click will make the top left corner page visible. 

Tip: The macro can be connected to the last Textbox/control’s (on the logical page) Lost_Focus() Event Procedure so that when the user presses the Tab Key the control will jump from one page to the next, without the help of a Command Button Click.

Now that we have everything in theory and have our master plan drawn out in a diagram, let us try it out on a form.  We will write the Macros for driving our Command Buttons first.

Create the Macros.

  1. Select Macro from the Create Menu to open a new Macro in design view.
  2. Click on the Macro Names control to open the Name column of the macro.
  3. Select the first row in Name column and type Page1-1.
  4. Select GotoPage from the drop-down control in the Action column.
  5. Select the Arguments column.
  6. Type 1 in the Page Number Action Arguments property below.
  7. Type 0 in the Right property and 0 in the Down property.
  8. Create the other three lines with the Argument values as shown in the image below:
  9. Save and close the Macro with the name MacPages.
  10. The Form Design.

  11. Open a new Form in Design View.
  12. Display the Property Sheet (F4).
  13. Click on the top left corner of the Form (Access2003) to select the Form’s Property Sheet, or select Form in the Selection Type box (Access2007) of the Property sheet.
  14. Change the Width Property value of the Form to 20 inch.
  15. Click on the Detail Section to display it’s property sheet.
  16. Change the Height Property Value to 10 inch.
  17. Select the Page-break Control from the Toolbox.
  18. Find the 5 inch position from the left side Scale and click near the left border on the Detail Section to place the Page-break control there.
  19. Create a Textbox control, about half an inch down on top left corner of the Form and change the child label Caption value as Page-1.
  20. Create a Command Button below the Textbox and change the following property values as shown below:
    • Caption  :  Go to 2
    • On Click  :  MacPages.Page1-2

      Tip: You may select the Macro Name from the drop-down list to avoid typing mistakes.

  21. Create a second Textbox to the right of the first one, about half an inch to the right of 10 inch scale location on top of the Form, and change the child label Caption to Page-2.
  22. Create a Command Button below the Text and change the following property values as shown below:
    • Caption  :  Go to 3
    • On Click  :  MacPages.Page2-1
  23. Create a Textbox below the Page-break control and change the child label Caption as Page-3.
  24. Create a Command Button below the Textbox and change the following property values as shown below:
    • Caption  :  Go to 4
    • On Click  :  MacPages.Page2-2
  25. Create a Textbox after the 10 inch location to the right and change the child label Caption as Page-4.
  26. Create a Command Button below the Textbox and change the following property values as given below:
    • Caption  :  Go to 1
    • On Click  :  MacPages.Page1-1
  27. Save the Form with a name.
  28. Test Run the Form.

  29. Open the Form in normal view and click on the Command Button to jump to the second page to the right.

    You will find that the form jumps to the second logical page to the right and the Textbox on this page is the active control.

  30. Try clicking on other Command Buttons to transfer control from one page to the next.

In all cases you will find that the textbox on the active logical page is the active control.


Accounting Year Week Calculations


Let us get straight into an issue in computerized calculations.  Most companies maintain their Books of Accounts for the Accounting Year starting from April 1st and ending on March 31st, next year.  So, April is the first month of the Accounting Year and 12th month is March next year. 

Here, our focus is on the Accounting Weeks calculations. If we need Weekly analysis of Sales or some other activities of the company how do we calculate week numbers starting from April 1-7 as Week 1 instead of January 1-7?  January 1 may sometimes end up as week 53 or 54, overlapping to next year based on the start of the week day.

We have the built-in Function DatePart() in Microsoft Access to calculate Week numbers based on the activity-date provided to the function as parameter.  Let us try an example of Datepart() function directly on the Debug Window.

Date is in dd-mm-yyyy format and Sunday is taken as first day of the week. The VBA Constant vbSunday represents the numeric value 1.

dt = DateValue("01-04-2011")
? DatePart("ww",dt,vbSunday)

Result: 14

The DatePart() built-in function returns the week number 14 instead of 1, for accounting-week calculation period April 1-7. This may fluctuate between 13 and 14, based on the first day of the Week being Sunday (used as second parameter to the above function) and the year. You will get the result 13 for April 1st, 2006.

If we want to create a weekly Sales Graph Chart for the first Quarter (first 13 weeks during April, May and June) of the Accounting Year we must convert the Sales date into their corresponding Week numbers in order to summarize the Sales values into weekly totals.

In short, the DatePart() function cannot be used directly to calculate Accounting months, weeks without some modifications. We can use the DatePart() function within Code of our own to modify the result to get the output we want.

Function: AccWeek().

I have written such a function AccWeek() to calculate week numbers from 01-04-yyyy to 31-03-yyyy.  This function mainly intended to call from the query column with activity-date as parameter (like Sale date, Payment date and so on) to return it’s corresponding week number.  You can use the function in your Code, on Form or Report or anywhere else you need it.

Copy and paste the following Code into a Standard Module in your Database and save it:

Public Function AccWeek(ByVal accDate As Date) As Integer
'Author : a.p.r.pillai
'Date   : June 2012
'All Rights Reserved by www.msaccesstips.com
Dim wkdayStart As Integer, wk As Integer, wkout As Integer
Dim accStart As Date, wksave As Integer, accStart1, accStart2

On Error GoTo AccWeek_Err
'First day of the week is taken Sunday as default
'If change is needed in your area please change the next line
wkdayStart = vbSunday
'calculate week number with built-in function
wk = DatePart("ww", accDate, wkdayStart)
'modify the week number according to accounting period
wksave = IIf(wk = 13 And ((Year(accDate) - 1) Mod 4) = 0, wk + 1, 13)
Select Case wk
      Case Is <= 13, 14
         wkout = DatePart("ww", DateValue("31-12-" & Year(accDate)), vbSunday) - wksave + wk
      Case Is > wksave
         wkout = wk - wksave
End Select

accStart1 = "01-04-" & Year(accDate)
accStart2 = "08-04-" & Year(accDate)

'Overlapped Week days check and reset week to 1
If (accDate >= accStart1) And (accDate < accStart2) Then
   wk = DatePart("ww", accDate, vbSunday)
   If wk > 1 Then
     wkout = 1
   End If
End If
AccWeek = wkout

Exit Function

MsgBox Err.Description, , "AccWeek()"
Resume AccWeek

End Function

Usage Example-1:

Calling AccWeek() Function from a Query Column:


Usage Example-2:

Use it in a Text Box on a Form or Report:


Usage Example-3:

Call from within your own Code:

intSaleWeek = AccWeek(dtSaleDate)

Note:AccWeek() Function is not extensively tested in field conditions and may use it at your own risk. If you find any logical errors in the code please share it with me too.

Technorati Tags:

MS-Access Tips on your Finger-Tip

  • Download Android App 'MSA Guru' Version of LEARN MS-ACCESS TIPS AND TRICKS from Google Play Store.

Want to Post Free Ads on the Web


Subscribe in a reader
Your email address:

Delivered by FeedBurner


Popular Posts

Blog Archive

Powered by Blogger.

Follow by Email


Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Menus and Toolbars Objects Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Dictionary Object Graph Charts Query VBA msaccessQuery Calculation Combo Boxes Event List Boxes Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Key Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances Item Macros Menus RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference TreeView Control Utility Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers ImageList Control Import Labels List ListView Control Logo Macro Mail Merge Main Form Memo Monitoring Nodes Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code