Introduction.
When we design a Form we will limit the placement of form controls within the visible area on the screen. Access 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 to our project.
There are four logical Page areas planned as shown above. But, in physical terms, there are only two pages, the top first-page area with two segments across, the first segment starting at coordinates 0,0 (0-inch horizontal starting point at left and a 0-inch vertical starting point at the top or top left corner). The second segment of the first page (or second logical page) starts at the 10-inch location from the left of the form and a 0-inch vertical position.
The size of a logical page is about 10 inches wide and 5 inches in height. 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 the 10-inch position from the 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 on the left side at the 5-inch vertical position is a page-break control, inserted from the Toolbox, to define the second physical page area (the third logical page area). This is also divided into two logical pages like we did on above the page-break control. The third logical page of the form, or the second physical page starts at 0 inches from the left and at the 0-inch position on the second page vertically (i.e. 5 inches down from the top of the form). The second logical page on the second physical page (or the fourth logical page) starts at the 10-inch position from the left of the form and the 0-inch position on the second physical page.
Ten-inch wide 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 the 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 Macros.
Select Macro from the Create menu to open a new Macro in the design view.
Click on the Macro Names control to open the Name column of the macro.
Select the first row in the Name column and type Page1-1.
Select GotoPage from the drop-down control in the Action column.
Select the Arguments column.
Type 1 in the Page Number Action Arguments property below.
Type 0 in the Right property and 0 in the Down property.
Create the other three lines with the Argument values as shown in the image below:
Save and close the Macro with the name MacPages.
Open a new Form in Design View.
Display the Property Sheet (F4).
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.
Change the Width Property value of the Form to 20 inches.
Click on the Detail Section to display its property sheet.
Change the Height Property Value to 10 inches.
Select the Page-break Control from the Toolbox.
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.
Create a Textbox control, about half an inch down on the top left corner of the Form, and change the child label Caption value as Page-1.
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.
Create a second Textbox to the right of the first one, about half an inch to the right of the 10-inch scale location on top of the Form, and change the child label Caption to Page-2.
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
Create a Textbox below the Page-break control and change the child label Caption as Page-3.
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
Create a Textbox after the 10-inch location to the right and change the child label Caption as Page-4.
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
Save the Form with a name.
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.
Try clicking on other Command Buttons to transfer control from one page to the next.
The Form Design.
Test Run the Form.
In all cases, you will find that the textbox on the active logical page is the active control.