Introduction
A sample image of an Employee's Form Design is given below:
When you view this screen in a maximized Application Window, the view will be something like the following image:
The normal view of the Employees Form, in maximized Application Windows, shows an empty stretch of space to the right of the data fields. The Form Title Employees stay where it is placed in a Label control, centralized over the data field controls.
Now, look at the following image taken after the Anchor Settings to the controls, which respond dynamically to move or stretch across the screen based on the resizing of the screen:
Compare the two images shown above. Notice how the layout changes automatically when the form window is maximized:
-
The second column of controls shifts neatly to the right edge of the screen.
-
The controls on the left side expand horizontally, filling up unused space and giving more room for data entry or viewing.
-
The form heading (“Employees”) realigns itself to the center of the screen.
-
The Note field (a memo field) stretches both downward and across, making it much easier to view and edit larger amounts of text.
Curious to know how this neat effect works in MS Access 2007? If you already have a form with a design similar to the one shown in the first image, you can try it out yourself — and here’s the best part: this trick works with any form!
Design a Form.
Let us design a Form with the Employees Table from the sample database Northwind.
Import the Employees Table from the Northwind sample database.
Create a form with a similar Design shown at the top of this page. You can use the Form Wizard to create the form in Column format and rearrange the controls.
Select all the controls of the second column together and move them down to get enough space for the Fax Number and Address fields, which we will bring from the first column, and place them on top of the second column.
Select Fax Number and Address Fields, and right-click on them to display the shortcut menu.
Select Cut from the menu to remove both text boxes and their child labels from the first column controls group.
Right-click somewhere in the Detail Section and select Paste to paste them back into the detail section.
Move the pasted controls and place them on top of the second column of controls.
Select and cut the Note Field and its child label from the second column and place them below the first column of controls.
Up to this point, everything we did was part of a standard form design process — arranging controls into columns as usual. However, there’s one important exception: the Note field. Instead of keeping it in the second column’s control group, we deliberately moved it below the first column as a standalone control. This way, it is no longer tied to the group’s layout behavior and can be assigned a different Anchoring property, allowing it to stretch independently when the form is resized.
Save the Form and open it in Form View to check what the current design looks like.
Implementing the Trick.
Change the Form in Design View.
Let’s begin applying these tricks to the controls on our form, starting from the top.
Step 1: Centering the Heading Label
We want the form heading to remain horizontally centered whenever the form is resized. If the text “Employees” in the header label is not already centered within its current width, select the label and click the Center button on the Design tab of the ribbon.Step 2: Making the Heading Responsive
Next, we want the label itself to stretch across the available width of the form so that the caption “Employees” always stays centered—whether the form is maximized or manually resized. To achieve this:-
Select the heading label control.
-
Open the Property Sheet (if not already open).
-
Locate the Anchoring property.
-
Change the setting to Stretch Across Top.
With this setting, the label automatically resizes with the form, and its caption remains centered no matter how the window is adjusted.
-
Click on the heading label to select it.
Select Arrange ->Anchoring -> Stretch Across Top.
Testing the Heading Label Behavior
-
Open the form in Normal View.
-
Maximize the window and check whether the form title Employees moves to the center across the expanded screen.
-
Next, manually resize the form:
-
Move the mouse pointer to the right edge of the form until it changes to the horizontal sizing arrow.
-
Hold down the left mouse button and slowly drag the edge inward.
-
Watch how the heading label automatically adjusts its width and keeps the caption centered.
-
-
For a quicker test, minimize the Navigation Pane and then display it again. The form window will expand and shrink instantly, showing the anchoring effect in action.
Moving On
Now that the header label behaves as expected, let’s play some anchoring tricks with the other controls in the Detail Section. This is where we’ll make the second column “stick” to the right edge and stretch the first column controls for better usability when resizing.
-
Place the Form back into Design View.
Highlight and select all the second column TextBoxes.
Select Arrange ->Anchoring -> Top Right or right-click on the selected controls and select Anchoring -> Top Right from the shortcut menu.
Change the form in Form View and preview the effect of our setting. Change the form back into Design View again.
Select the TextBoxes in the left column, except the Note field.
Right-click on the controls and select Anchoring -> Stretch Across Top.
Select the Notes field, right-click on the control, and select Anchoring -> Stretch Down and Across.
All the anchoring settings are now complete. Save the form and switch to Normal View. Try resizing the form window manually—dragging the edges slowly—to watch how each control responds in slow motion. You’ll see the title label, the right-side controls, and the Note field all adapt smoothly to the changing form size.











No comments:
Post a Comment
Comments subject to moderation before publishing.