Adding Controls to a Form


Every form has three basic sections: Form Header, Detail, and Form Footer. When you use the Form tool or a wizard to create a form, they add a set of controls for each field that you select from the underlying table to the Detail section, add a logo placeholder and/or caption to the Form Header, and leave the Form Footer section blank. Because the Footer section is empty, Access collapses it, but you can resize the Footer section by dragging its selector. Although labels and text box controls are perhaps the most common controls found in forms, you can also enhance your forms with many other types of controls. For example, you can add groups of option buttons, check boxes, and list boxes to present people with choices instead of having them type entries in text boxes.

The controls that you can add to a form are located on the Design tab in the Controls group.

In this exercise, you will replace the logo and caption automatically placed in a form by the Form tool. You will also replace a text box control in the Detail section with a combo box control, and remove the record selector bar from the program window.

USE the 04_AddControls database and the 04_CustomersFormLogo graphic. These practice files are located in the Chapter05 subfolder under SBS_Access2007.

OPEN the 04_AddControls database. Then open the Customers form in Design view.


1.

In the Customers form, point to the horizontal line between the Form Header section selector and the Detail section selector, and when the pointer changes to a double-headed arrow, drag the Detail section selector down a little more than an inch.

Tip

Use the rulers along the top and left side of the form as guides.

2.

Select the logo and the caption in the Form Header, and then press .

3.

On the Design contextual tab, in the Controls group, click the Image button, and then, at the left end of the Form Header section, drag diagonally to draw a rectangle about 1 inch high and 1.5 inches wide.

Image

To view information about a control, point to its button in the Controls group. After a few seconds a ScreenTip is displayed.

Tip

Access 2007 has a new Logo control that prompts you to enter a graphic name, and then automatically inserts the graphic in the form header.

4.

In the Insert Picture dialog box, navigate to the Documents\MSP\SBS_Access2007\Chapter05 folder, and then double-click the 04_CustomersFormLogo graphic.

Troubleshooting

If the practice file isn't visible, change the Files Of Type setting to Graphics Files.

The logo appears inside the image control.

Tip

How an image fits into an image control is determined by the Size Mode property of the control. If the property is set to Clip and the control isn't large enough to display the entire image, the image is cropped. If the property is set to Stretch, you can enlarge the control to display the entire image. If the property is set to Zoom, the image will automatically resize to fit the control.

5.

In the Controls group, click the Label button, and then drag diagonally to draw another rectangle in the header section.

Access inserts a label control containing the insertion point, ready for you to enter a caption.

6.

In the active label control, type Customers. Then press .

The Customers label takes on the formatting of the other labels.

Troubleshooting

Access displays a Smart Tag next to the control, warning you that the label is not associated with any other control. You can ignore this, or click Ignore Error to make it go away.

7.

If the Property Sheet pane is not already open, press to open it.

Tip

You can toggle the display of the Property Sheet pane by pressing the F4 key.

8.

Change the Font Size property to 18, and the Text Align property to Center. Then close the Property Sheet pane.

9.

On the Arrange tab, in the Size group, click the Size to Fit button.

Size to Fit

The size of the label control changes to fit the text.

10.

Adjust the size and position of the image and label controls so that they are side-by-side.

11.

On the Design tab, in the Controls group, look at the Use Control Wizards button. If the button is active (orange), click it to deactivate it.

Use Control Wizards

Turning off the Control Wizards feature enables you to add a control with all the default settings, without having to work through the wizard's pages.

12.

In the Controls group, click the Combo Box button. Then drag diagonally to draw a rectangle just below the Country text box.

Combo Box

When you release the mouse button, Access displays a combo box control, which is unbound (not attached to a field in the Customers table).

Troubleshooting

Access assigns a number to each control when it is created. Don't be concerned if the number displayed in your control is different from what you see in the graphics in this book.

13.

Click the Country text box. In the Font group, click the Format Painter button and then click the combo box control.

Format Painter

Access copies the formatting of the text box to the combo box control and its label.

14.

If the Property Sheet pane is not open, right-click the combo box, and then click Properties.

15.

In the Property Sheet pane, on the Data tab, click the Control Source arrow, and then in the list, click Country.

16.

In the Row Source box, type

SELECT DISTINCT Customers.Country FROM Customers;

There is a period (but no space) between Customers and Country, and a semicolon at the end of the text.

This line of code is a query that extracts one example of every country in the Country field of the Customers table and displays the results as a list when you click the Country arrow.

You might have to widen the Property Sheet pane to display the entire query.

Tip

If you need to add a customer from a country that is not in the list, you can type the country's name in the combo box. After the record is added to the database, that country shows up when the combo box list is displayed.

17.

If it isn't already, set the Row Source Type to Table/Query.

18.

Click the combo box label. (If you can't see the combo box label, move the Property Sheet pane.)

19.

In the Property Sheet pane, on the Format tab, change the Caption to Country. Then close the Property Sheet pane.

20.

Delete the original Country text box and its label, and then move the new combo box and label into their place, resizing them as needed.

21.

On the Home tab, in the Views group, click the View button to see your form in Form view.

Tip

When a form is in Layout view or Design view, you can switch to Form view by clicking the View button.

22.

Scroll through a couple of records, and then click the combo box arrow to display the country list.

23.

You don't need the record selectorthe gray bar along the left edge of the formfor this exercise, so return to Design view and display the Property Sheet pane for the entire form by clicking the Form selector (the box at the junction of the horizontal and vertical rulers) and pressing (if the sheet is not already displayed). Then on the Format tab, change Record Selectors to No, and Scroll Bars to Neither. Then press again to close the Property Sheet pane.

24.

Save the form's new design, and then switch to Form view for a final look.

CLOSE the 04_AddControls database.




MicrosoftR Office AccessT 2007 Step by Step
MicrosoftR Office AccessT 2007 Step by Step
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net