Placing Controls on Forms

3 4

To begin, you’ll need to create a form on which you can place your controls. Choose Insert, Form to open the New Form dialog box. Select Design View from the list of selections, select the table or query containing the data to display on the form, and then click OK. The new, blank, form appears in Design view. You can manually place controls on a form in two ways: by using the Toolbox and by using the field list.

See the "Using the Field List to Place a Control" section for more information about using the field list; also see Chapter 5, "Creating Forms for Entering, Editing, and Viewing Data," for information about creating various types of forms.

Fields added to a form from the field list are always inserted as text box controls, with two exceptions: Yes/No fields are inserted as check boxes, and Lookup fields are inserted as combo boxes. If you want to insert text box controls bound to fields, the fastest way is to drag the fields from the field list; otherwise, click the tool icon for the type of control you want to use in the Toolbox and then click the form to insert an unbound control, or drag the field from the field list to insert a bound control of the selected control type. Alternatively, you can click the appropriate tool, click the form to place a control, and then select the control’s Control Source property from its properties sheet.

For example, if you want to insert a field as a combo box, click the Combo Box tool in the Toolbox and then drag the field from the field list to the form. A combo box bound to the selected field is placed on the form.

Troubleshooting - When I try to select a field for a control’s Control Source property, there’s no drop-down list of fields to select from

If no fields appear in the drop-down list, the form is unbound. To correct this, select a record source for the form, as follows:

  • Click the Form Selector in the upper left corner of the form window.
  • Click the Properties button on the Form Design toolbar to open the properties sheet for the form.
  • Click the Data tab, and choose the name of the table or query you want to bind the form to in the Record Source property combo box.

Data-Bound Controls vs. Unbound Controls

Bound controls display data from a field in the form’s record source, whereas unbound controls are not linked to data. Some controls can be either bound or unbound (such as text boxes), whereas others are bound only (the bound object frame) or unbound only (labels). Table 6-1 lists some of the most commonly used controls and indicates whether they can be bound or unbound.

Table 6-1. Bound and unbound controls

Control

Bound

Unbound

Label

X

Text Box

X

X

Option Group

X

X

Toggle Button

X

X

Option Button

X

X

Check Box

X

X

Combo Box

X

X

List Box

X

X

Command Button

X

Image

X

Unbound Object Frame

X

Bound Object Frame

X

Page Break

X

Tab Control

X

Subform/Subreport

X

X

Line

X

Rectangle

X

Some controls that can be either bound or unbound are genuinely useful in both modes (such as text boxes and combo boxes); others (such as toggle buttons and check boxes) are useful only when bound. See the sections on individual controls for more details about using controls in bound or unbound states.

Using the Toolbox to Place a Control on a Form

To place a control on a form using the Toolbox, click the tool you want to use and click on the form where you want to place the control. You can also click and drag on the form to control the size and position of the control as it is placed on the form. Figure 6-1 shows the various tools available in the Toolbox.

figure 6-1. the toolbox contains tools representing the controls that can be added to access forms in design view.

Figure 6-1. The Toolbox contains tools representing the controls that can be added to Access forms in Design view.

Tools and Controls

The buttons you see in the Toolbox are called tools. Most of them represent controls you can place on a form or report. To avoid confusion, this book will refer to the control-inserting tools on the Toolbox as tools and the controls they place on forms as controls. For example, the List Box tool on the Toolbox is used to place a list box control on a form.

The tools in the Toolbox are described in the following list. Some of the tools (Select Objects, Control Wizards, More Controls, and Toolbar Options) aren’t used to insert controls; they are tools you use to work with controls or with the Toolbox itself.

Select Objects. When this tool is enabled, you can select controls on a form to move or resize them. This tool is enabled by default when no other tool in the Toolbox is selected; it is temporarily disabled when another tool is clicked.

Control Wizards. A Control Wizard is a dialog box that guides you through the process of associating data in a table or query with a control or creating a simple event procedure for the control. Clicking this tool enables Control Wizards so that when you select a control to add to the form, the appropriate Control Wizard appears, to guide you through creating the control. The following controls have Control Wizards:

  • Combo Box
  • Command Button
  • Label
  • List Box
  • Option Group
  • Subform/Subreport

Label. Use this control to display descriptive text. Labels are always unbound.

Text Box. This control displays data from a field, the results of an expression, or text entered by the user.

Option Group. This control presents the user with a set of choices, only one of which can be selected at a time.

Toggle Button. When you bind a toggle button to a Yes/No field, the button is up to indicate Yes or down to indicate No.

Option Button. Use this control to indicate a choice. (A black center means that an option is selected.)

Check Box. This control also indicates a choice. (A check mark means that the item is selected.)

Combo Box. This control presents a drop-down list of selections to choose from and also allows text entry.

List Box. This control displays a full list of selections with no option for manual entry.

Command Button. This control performs an action by running an event procedure or a macro.

Image. This control displays an unbound image (an image that is not stored in an Access table).

Unbound Object Frame. This control displays an unbound OLE object, such as a Microsoft Excel spreadsheet.

Bound Object Frame. This control displays a bound object, such as an image stored in the form’s record source.

Page Break. This control indicates a new form page.

Tab Control. This control displays information in groups, each on a tabbed page.

Subform/Subreport. This control displays information from a form, query, or table.

Line. Use this control to add a decorative line to your form.

Rectangle. Use this tool to add a decorative rectangle to your form.

More Controls. Use this tool to open a list of ActiveX controls that you can place on a form.

Toolbar Options. This tool allows you to add or remove Toolbox tools by means of a menu, shown in Figure 6-2.

caution


The list that you open with the More Controls tool includes all the ActiveX controls available to any applications on your computer; the list isn’t limited to the controls that work on Access forms.

figure 6-2.you can add or remove toolbox tools with this menu.

Figure 6-2. You can add or remove Toolbox tools with this menu.

Depending on your screen size and resolution, you might not be able to see all the tools in the Toolbox. If that’s the case, a double chevron will appear at the bottom (or right side) of the Toolbox. Click the double chevron to see the missing tools displayed on a submenu as shown in Figure 6-3.

figure 6-3. a submenu displays extra tools not visible on the toolbox.

Figure 6-3. A submenu displays extra tools not visible on the Toolbox.

Using the Field List to Place a Control

The field list is a dialog box containing a list of the fields in the table or query that is the form’s record source. You can place a control on a form manually by dragging a field from the field list. Access selects the control type based on the field type. As shown in Figure 6-4, the Current field in tblCategories (the table used as the form’s record source) is a Yes/No field, so it’s placed on the form as a bound check box. (This table is located in the sample Controls 2002 database on the book’s CD.)

figure 6-4. you can drag a yes/no field from the field list to a form to create a bound check box.

Figure 6-4. You can drag a Yes/No field from the field list to a form to create a bound check box.

tip


If the field list isn’t visible, press F8 to open it.

caution


You can choose the specific control type for a field by clicking the appropriate tool in the Toolbox and then dragging the field from the field list. However, nothing will prevent you from creating an inappropriate control for a field, such as a check box control for a text field. Generally, it’s best to let Access select the appropriate control type for fields.

Figure 6-5 shows a form with at least one of each type of control. Some controls appear in two modes: For example, the label control appears as both a stand-alone label and an attached label. Notice that the option button is also displayed in two modes: a stand-alone option button on the right side of the form and a set of option buttons in an option group on the left side of the form (frmTestControls, in the Controls 2002 database).

figure 6-5. this form has at least one of each type of control.

Figure 6-5. This form has at least one of each type of control.

tip - Drag a group of fields


To drag all the fields in the field list to a form, double-click the field list’s title bar (this highlights all the fields), and then drag the fields to the form as a group. To select more than one (but not all) fields, click the first field, and then use the Ctrl+click hot key to select the other fields (that is, press Ctrl and click to select each individual field). To select a group of contiguous fields, use the Shift+click hot key (that is, click the first field in the group and then press Shift and click on the last field to select all fields between).

tip


If you make a mistake in dragging or resizing a control, press Ctrl+Z immediately to undo the action.



Microsoft Access Version 2002 Inside Out
Microsoft Access Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612838
EAN: 2147483647
Year: 2005
Pages: 172
Authors: Helen Feddema

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