IN THIS CHAPTER
Creating different types of forms
Adding controls to a form
Working with the Property Sheet
Viewing and modifying data in Form view
Printing a form
Adding calculated controls to a form
Converting a form to a report
Forms provide the most flexible way for viewing, adding, editing, and deleting your data. They’re also used for switchboards (forms with buttons that provide navigation), for dialog boxes that control the flow of the system, and for messages. Controls are the objects on forms such as labels, text boxes, buttons, and many others. In this chapter, you learn how to create different types of forms and learn about the types of controls that are used on a form. This chapter also discusses form and control properties and how you determine the appearance and behavior of an Access interface through setting or changing property values.
The forms you add to an Access database are a critical aspect of the application you create. In most situations, users should not be permitted direct access to tables or query datasheets. It’s far too easy for a user to delete valuable information or incorrectly input data into the table. Forms provide a useful tool for managing the integrity of a database’s data. Because forms can contain VBA code or macros, a form can verify data entry or confirm deletions before they occur. Also, a properly designed form can reduce training requirements by helping the user understand what kind of data is required by displaying a message as the user tabs into a control. A form can provide default values or perform calculations based on data input by the user or retrieved from a database table.
Use the Forms group on the Create tab of the Ribbon to add forms to your database. The commands in the Forms group — shown in Figure 35.1 — let you create the following different types of forms and ways to work with Access forms:
If any of the terminology in the preceding bullets is new to you, don’t worry — each of these terms is discussed in detail in this chapter. Keep in mind that the Access Ribbon and its contents are very context dependent, so every item may not be available when you select the Create tab.
Like many other aspects of Access development, Access provides multiple ways of adding new forms to your application. The easiest is to select a data source, such as a table, and click the Form command on the Create tab of the Ribbon. Another is to use the Form Wizard and allow the wizard to guide you through the process of specifying a data source and other details of the new form.
Use the Form command in the Forms group of the Ribbon to automatically create a new form based on a table or query selected in the Navigation pane.
To create a form based on a table, follow these steps:
The new form is opened in Layout view, which is populated with controls, each of which is bound to a field in the underlying data source. Layout view gives you a good idea how the controls appear relative to one another, but it provides only limited ability to resize controls or move controls on the form. Right-click the form’s title bar and select Design View to rearrange controls on the form.
The Form Design button in the Forms group does essentially the same thing as the Form button, except that no controls are added to the form’s design surface and the form is opened in Design view. Form Design is most useful when you’re creating a new form that might not use all the fields in the underlying data source, and you want more control over control placement from the start.
Similarly, the Blank Form option opens a new empty form, but this time in Layout view. You add controls to the form’s surface from the Field List, but you have little control over control placement. The Blank Form option is most useful for quickly building a form with bound controls with little need for precise placement. A new blank form can be produced in less than a minute.
Use the Form Wizard command in the Forms group to create a form using a wizard. The Form Wizard visually walks you through a series of questions about the form that you want to create and then creates it for you automatically. The Form Wizard lets you select which fields you want on the form, the form layout (Columnar, Tabular, Datasheet, Justified), and the form title.
To start the Form Wizard and use it create a form, follow these steps:
When working with Access, the word form can mean any of several different things, depending on context. This section discusses several different ways that “forms” are used in Access and presents an example of each usage.
Access 2010 introduced an entirely new form intended specifically as a navigation tool for users. Navigation forms include a number of tabs that provide instant access to any number of other forms in a form/subform arrangement. The Navigation button on the Ribbon offers a number of button placement options (shown in Figure 35.6). Horizontal Tabs is the default.
Selecting a tab placement in the Navigation drop-down list opens the new navigation form in Design view (see Figure 35.7). The new form includes a row of tabs along the top and a large area under the tabs for embedding subforms. You type the tab’s label (like Products) directly into the tab, or add it through the tab’s Caption property. As you complete the tab’s label, Access adds a new, blank tab to the right of the current tab.
In Figure 35.7, the Horizontal Tabs option was selected when choosing a navigation form template and a tab was named Products, which generates a new Add New tab. The alternatives to Horizontal Tabs (Vertical Tabs, Left, Vertical Tabs, Right, and so on) are shown in Figure 35.6.
The example Product tab’s Property Sheet (shown in Figure 35.8) includes the Navigation Target Name property for specifying the Access form to use as the tab’s subform. Select a form from the drop-down list in the Navigation Target Name property, and Access creates the association to the subform for you.
The completed navigation form is shown in Figure 35.9. The auto-generated navigation form makes extravagant use of screen space. There are a number of things that could be done to enhance this form, such as removing the navigation form’s header section and reducing the empty space surrounding the subform.
Click the More Forms button in the Forms group of the Ribbon and then click the Multiple Items button to create a tabular form based on a table or query selected in the Navigation pane. A tabular form is much like a datasheet, but it’s much more attractive than a plain datasheet.
Because the tabular form is truly an Access form, you can convert the default text box controls on the form to combo boxes, list boxes, and other advanced controls. Tabular forms display multiple records at one time, which makes them very useful when you’re reviewing or updating multiple records. To create a multiple-items form based on a table, follow these steps:
Click the More Forms button in the Form group of the Ribbon and then click the Split Form button to create a split form based on a table or query selected in the Navigation pane. The split-form feature gives you two views of the data at the same time, letting you select a record from a datasheet in the lower section and edit the information in a form in the upper section.
To create a split form based on a table, follow these steps:
The Split Form Orientation property (on the Format tab of the form’s Property Sheet) determines whether the datasheet is on the top, bottom, left, or right of the form area. The default is as shown in Figure 35.11, with the datasheet area on the bottom.
Click the More Forms button in the Forms group of the Ribbon and then click the Datasheet button to create a form that looks like a table or query’s datasheet. A datasheet form is useful when you want to see the data in a row and column format, but you want to limit which fields are displayed and editable.
To create a datasheet form based on a table, follow these steps:
The area with gridlines in the form is where you work. This is the size of the form when it’s displayed. Resize the grid area of the form by dragging any of the area borders to make it larger or smaller. Figure 35.12 shows a blank form in Design view being resized.
You can save the form at any time by clicking the Save button in the Quick Access Toolbar. When you’re asked for a name for the form, give it a meaningful name (for example, frmProducts, frmCustomers, or frmProductList.) Once you’ve given the form a name, you won’t be prompted the next time you click Save.
When you close a form after making changes, Access asks you to save it. If you don’t save a form, all changes since you opened the form (or since you last clicked Save) are lost. You should frequently save the form while you work if you’re satisfied with the results.
Controls and properties form the basis of forms and reports. It’s critical to understand the fundamental concepts of controls and properties before you begin to apply them to custom forms and reports.
The term control has many definitions in Access. Generally, a control is any object on a form or report, such as a label or text box. These are the same sort of controls used in any Windows application, such as Access, Excel, web-based HTML forms, or those that are used in any language, such as .NET, Visual Basic, C++, or C#. Although each language or product has different file formats and different properties, a text box in Access is similar to a text box in any other Windows product.
You enter data into controls and display data using controls. A control can be bound to a field in a table (when the value is entered in the control, it’s also saved in some underlying table field), or data can be unbound and displayed in the form but not saved when the form is closed. A control can also be an object, such as a line or rectangle.
Some controls that aren’t built into Access are developed separately — these are ActiveX controls. ActiveX controls extend the basic feature set of Access and are available from a variety of vendors.
Whether you’re working with forms or reports, essentially the same process is followed to create and use controls. In this chapter, I explain controls from the perspective of a form.
Forms and reports contain many different types of controls. You can add these controls to forms using the Controls group on the Form Design Tools ⇒ Design tab, or Form Layout Tools ⇒ Arrange tab shown in Figure 35.13. Hovering the mouse over the control displays a ScreenTip telling you what the control is.
Table 35.1 briefly describes the basic Access controls.
Control | What It Does |
Text Box | Displays and allows users to edit data. |
Label | Displays static text that typically doesn’t change. |
Button | Also called a command button. Runs macros or VBA code when clicked. |
Combo Box | A drop-down list of values. Combo boxes include a text box at the top for inputting values that are not included in the drop-down list. |
List Box | A list of values that is always displayed on the form or report. |
Subform/Subreport | Displays another form or report within the main form or report. |
Line | A graphical line of variable thickness and color, which is used for separation. |
Rectangle | A rectangle can be any color or size or can be filled in or blank; the rectangle is used to group related controls visually. |
Image | Displays a bitmap picture with very little overhead. |
Option Group | Holds multiple option buttons, check boxes, or toggle buttons. |
Check Box | A two-state control, shown as a square that contains a check mark if it’s on and an empty square if it’s off. Before a Check Box’s value is set, it appears as a grayed-out square. |
Option Button | Also called a radio button, this button is displayed as a circle with a dot when the option is on. |
Toggle Button | This is a two-state button — up or down — which usually uses pictures or icons instead of text to display different states. |
Tab Control | Displays multiple pages in a file folder type of interface. |
Page | Adds a page on the form or report. Additional controls are added to the page, and multiple pages may exist on the same form |
Chart | Displays data in a graphical format. |
Unbound Object Frame | Holds an OLE object or embedded picture that isn’t tied to a table field and can include graphs, pictures, sound files, and video. |
Bound Object Frame | Holds an OLE object or embedded picture that is tied to a table field. |
Page Break | Usually used for reports and indicates a physical page break. |
Hyperlink | Creates a link to a web page, a picture, an e-mail address, or a program. |
Attachment | Manages attachments for the Attachment data type. Attachment fields provide a way to attach external files (such as music or video clips or Word documents) to Access tables. |
The Use Control Wizards button, revealed by expanding the Controls group by clicking on the More button in the lower-right corner of the group, doesn’t add a control to a form. Instead, the Use Control Wizards button determines whether a wizard is automatically activated when you add certain controls. The Option Group, Combo Box, List Box, Subform/Subreport, Bound and Unbound Object Frame, and Command Button controls all have wizards to help you when you add a new control. You can also use the ActiveX Controls button (also found at the bottom of the expanded Controls group) to display a list of ActiveX controls, which you can add to Access.
There are three basic categories of controls:
You add a control to a form in a number ways:
When you use the buttons in the Controls group to add a control, you decide which type of control to use for each field. The control you add is unbound (not attached to the data in a table field) and has a default name such as Text21 or Combo11. After you create the control, you decide what table field to bind the control to, enter text for the label, and set any properties. You’ll learn more about setting properties later in this chapter.
You can add one control at a time using the Controls group. To create three different unbound controls, for example, you would perform these steps:
The Field List displays a list of fields from the table or query the form is based on. Open the Field List by clicking the Add Existing Fields button in the Tools group on the Form Design Tools ⇒ Design tab of the Ribbon (refer to Figure 35.13).
If you created a form using a method that automatically binds the form to a table or query, the field list for that table or query will be displayed. For this example, we created a form using the Blank Form button, which does not automatically bind the form to a datasource. In this case, the Field List only shows a Show All Tables link. Click the Show All Tables link to get a list of tables. Then click the plus sign next to the desired table to show the fields in that table.
Drag a field from the Field List and drop it onto the form to create a control bound to that field on the form. You can select and drag fields one at a time or select multiple fields by using the Ctrl key or Shift key:
By default, the Field List appears docked on the right of the Access window. The Field List window is movable and resizable and displays a vertical scroll bar if it contains more fields than can fit in the window. Figure 35.15 shows the Field List undocked and moved on top of the form.
Most often, dragging a field from the Field List adds a bound text box to the Design window. If you drag a Yes/No field from the Field List window, Access adds a check box. Optionally, you can select the type of control by selecting a control from the Controls group and dragging the field to the Design window.
You gain several distinct advantages by dragging a field from the Field List window:
In the example in Figure 35.16, the Description, Category, RetailPrice, and Cost fields were selected in the Field List window and dragged to the form. Double-clicking a field also adds it to the form.
You can see four new pairs of controls in the form’s Design view — each pair consists of a Label control and a Text Box control (Access attaches the Label control to the Text Box automatically). You can work with these controls as a group or independently, and you can select, move, resize, or delete them. Notice that each control has a label with a caption matching the field name, and the Text Box control displays the bound field name used in the text box. If you want to resize just the control and not the label, you must work with the two controls (label and associated text box) separately. You’ll learn about working with labels attached to controls later in this chapter.
Close the Field List by clicking the Add Existing Fields command in the Tools group of the Design tab or by clicking the Close button on the Field List.
In the “Introducing Properties” section, later in this chapter, you learn how to change the control names, captions, and other properties. Using properties speeds the process of naming controls and binding them to specific fields. If you want to see the differences between bound and unbound controls, switch to Form view using the View command in the View group of the Ribbon. Bound controls display data from the table that they’re bound to. Unbound controls don’t display data because they aren’t bound to any data source.
After you add a control to a form, you can resize it, move it, or copy it. The first step is to select one or more controls. Depending on its size, a selected control might show from four to eight handles (small squares called moving and sizing handles) around the control — at the corners and midway along the sides. The move handle in the upper-left corner is larger than the other handles and you use it to move the control. You use the other handles to size the control. Figure 35.17 displays some selected controls and their moving and sizing handles.
The Select command (which looks like an arrow) in the Controls group of the Design tab must be chosen in order for you to select a control. If you use the Controls group to create a single control, Access automatically reselects the pointer as the default.
Select any individual control by clicking anywhere on the control. When you click a control, the sizing handles appear. If the control has an attached label, the move handle for the label also appears in the upper-left corner of the control. If you select a label control that is associated with another control, all the handles for the label control are displayed, and only the move handle appears in the associated control.
You select multiple controls in these ways:
Figure 35.17 shows the result of selecting the multiple bound controls graphically. When you select multiple controls by dragging the mouse, a rectangle appears as you drag the mouse. Be careful to drag the rectangle only through the controls you want to select. Any control you touch with the rectangle or enclose within it is selected. If you want to select labels only, make sure that the selection rectangle only touches the labels.
Deselect a control by clicking an unselected area of the form that doesn’t contain a control. When you do so, the handles disappear from any selected control. Selecting another control also deselects a selected control.
Creating a form is a multistep process. The next step is to make sure that your controls are properly sized and moved to their correct positions. The Form Design Tools ⇒ Arrange tab or Form Layout Tools ⇒ Arrange tab (shown in Figure 35.18) contains commands used to assist you in manipulating controls.
You resize controls using any of the smaller handles in the upper, lower, and right edges of the control. The sizing handles in the control corners let you drag the control larger or smaller in both width and height — and at the same time. Use the handles in the middle of the control sides to size the control larger or smaller in one direction only. The top and bottom handles control the height of the control; the left and right handles change the control’s width.
When the mouse pointer touches a corner sizing handle of a selected control, the pointer becomes a diagonal double arrow. You can then drag the sizing handle until the control is the desired size. If the mouse pointer touches a side handle in a selected control, the pointer changes to a horizontal or vertical double-headed arrow. Figure 35.19 shows the Description control after being resized. Notice the double-headed arrow in the corner of the Description control.
When you double-click on any of the sizing handles, Access resizes a control to best fit the text contained in the control. This feature is especially handy if you increase the font size and then notice that the text is cut off either at the bottom or to the right. For label controls, note that this best-fit sizing adjusts the size vertically and horizontally, though text controls are resized only vertically. This is because when Access is in Form Design view, it can’t predict how much of a field to display — the field name and field contents can be radically different. Sometimes, Access doesn’t correctly resize the label and you must manually change its size.
Clicking the Size/Space button in the Sizing & Ordering group of the Arrange tab opens a menu with several commands that help you arrange controls:
After you select a control, you can easily move it, using either of these methods:
Figure 35.20 shows a Label control that has been separately moved to above a Text Box control.
Press Esc before you release the mouse button to cancel a moving or a resizing operation. After a move or resizing operation is complete, click the Undo button on the Quick Access Toolbar to undo the changes, if needed.
You might want to move several controls so that they’re all aligned. The Sizing & Ordering group’s Align menu choices on the Arrange tab contains the following alignment commands:
You can align any number of selected controls by selecting an align command. When you choose one of the align commands, Access uses the control that’s the closest to the desired selection as the model for the alignment. For example, suppose that you have three controls and you want to left-align them. They’re aligned on the basis of the control farthest to the left in the group of the three controls.
Figure 35.21 shows several sets of controls. The first set of controls is not aligned. The label controls in the middle set of controls have been left-aligned while the text box controls in the right-side set have been right-aligned.
Each type of alignment must be done separately. In this example, you can left-align all the labels or right-align all the text boxes at once.
By default, Access displays a series of small dots across the entire surface of a form while it’s in Design view. The grid can assist you in aligning controls. Hide or display the grid by selecting the Grid command from the Size/Space gallery under the Sizing & Ordering group on the Arrange tab of the Ribbon. You can also hide or display the ruler using the Ruler command in the same gallery.
Use the Snap to Grid command in the Size/Space menu to align controls to the grid as you draw or place them on a form. This also aligns existing controls to the grid when you move or resize them.
As you move or resize existing controls, Access lets you move only from grid point to grid point. When Snap to Grid is off, Access ignores the grid and lets you place a control anywhere on the form or report.
Click Size/Space in the Sizing & Ordering group on the Arrange tab to access commands to adjust spacing between controls. The spacing commands adjust the distance between controls on the basis of the space between the first two selected controls. If the controls are across the screen, use horizontal spacing; if they’re down the screen, use vertical spacing. The commands in the Spacing group of the Size/Space menu are
To modify the appearance of a control, select the control and click commands that modify that control, such as the options in the Font or Controls group. Follow these steps to change the text color and font of an example label:
To modify the appearance of multiple controls at once, select the controls and click commands to modify the controls, such as commands in the Font or Controls group. To change the text color and font for multiple labels and text boxes, for example, follow these steps:
When multiple controls are selected, you can also move the selected controls together. When the mouse pointer changes to the four-directional arrow, drag to move the selected controls. You can also change the size of all the controls at once by resizing one of the controls in the selection. All the selected controls increase or decrease by the same number of units.
If you routinely change properties of multiple controls, you might want to group them together. To group controls together, select the controls by holding down the Shift key and clicking them or dragging over them. After the desired controls are selected, select Arrange ⇒ Sizing & Ordering ⇒ Size/Space ⇒ Group. Then, when one control in a group is selected, all controls in that group are automatically selected, as shown in Figure 35.23.
Double-click a control to select just one control in a group. After a single control in the group is selected, you can click any other control to select it.
To resize the entire group, point to the side you want to resize. After the double arrow pointer appears, drag until you reach the desired size. Every control in the group changes in size. To move the entire group, drag the group to its new location. With grouped controls, you don’t have to select all the controls every time you change something about them.
To remove a group, select the group by clicking any field inside the group, and then select Arrange ⇒ Sizing & Ordering ⇒ Size/Space ⇒ Ungroup.
Although there are times you may want to use a check box to display a Boolean (yes/no) data type, there are other ways to display the value, such as a toggle button, as shown in Figure 35.24. A toggle button is raised if it’s true and pressed if it’s false.
Use these steps to turn a check box into a toggle button:
You can create copies of any control by copying it to the Clipboard and then pasting the copies where you want them. If you have a control for which you’ve entered many properties or specified a certain format, you can copy it and revise only the properties (such as the control’s name and bound field name) to make it a different control. This capability is useful with a multiple-page form when you want to display the same values on different pages and in different locations, or when copying a control from one form to another.
You can delete a control by simply selecting it in the form’s Design view and pressing the Delete key on your keyboard. The control and any attached labels will disappear. You can bring them back by immediately selecting Undo from the Quick Access Toolbar. You can also select Cut from the Clipboard group on the Home tab of the Ribbon, or Delete from the Records group on the Home tab of the Ribbon.
You can delete more than one control at a time by selecting multiple controls and pressing Delete. You can delete an entire group of controls by selecting the group and pressing Delete. If you have a control with an attached label, you can delete only the label by clicking the label itself and then selecting one of the delete methods. If you select the control, both the control and the label are deleted.
If you accidentally delete a label from a control, you can reattach it. To create and then reattach a label to a control, follow these steps: Later in this chapter, in the “Naming control labels and their captions” section, you’ll learn about the special relationship between a control and its label. By default, Access controls include a label when the control is added to a form; this label moves around with the control as you reposition the control on the form. The “Naming control labels and their captions” section describes these behaviors and how to work with control labels.
Another way to attach a label to a control is to select the label control and then click the information button next to the label, shown in Figure 35.25. This information button lets you know that the selected label is unassociated with a control. Select the Associate Label with a Control command from the menu, and then select the control you want to associate the label with.
Properties are named attributes of controls, fields, or database objects that are used to modify the characteristics of a control, field, or object. Examples of these attributes are the size, color, appearance, or name of an object. A property can also modify the behavior of a control, determining, for example, whether the control is read-only or editable and visible or not visible.
Properties are used extensively in forms and reports to change the characteristics of controls. Each control on the form has properties. The form itself also has properties, as does each of its sections. The same is true for reports; the report itself has properties, as does each report section and individual control. The label control also has its own properties, even if it’s attached to another control.
Everything that you do with the Ribbon commands — from moving and resizing controls to changing fonts and colors — can be done by setting properties. In fact, all these commands do is change properties of the selected controls.
Properties are displayed in a Property Sheet (sometimes called a Property window). To display the Property Sheet for a control in Form Design view, follow these steps:
Because the Property Sheet is a window, it can be undocked, moved, and resized. It does not, however, have Maximize or Minimize buttons.
There are several ways to display a control’s Property Sheet if it isn’t visible:
With the Property Sheet displayed, click any control in Design view to display the properties for that control. Select multiple controls to display similar properties for the selected controls. The vertical scroll bar lets you move among various properties.
The Property Sheet has an All tab that lets you see all the properties for a control. Or you can choose another tab to limit the view to a specific group of properties. The specific tabs and groups of properties are as follows:
Figure 35.26 shows the Property Sheet for a Description text box selected on the form. The first column lists the property names; the second column is where you enter or select property settings or options. You can use the drop-down list near the top of the Property Sheet (displaying Description in Figure 35.26) to change which control’s properties are shown. The drop-down list also enables you to select other objects on the form, like the Detail section, Form Header, or the Form itself.
There are many different methods for changing property settings, including the following:
You can change a control’s properties by clicking a property and typing the desired value.
In Figure 35.27, you see a down arrow and a button with three dots to the right of the Control Source property entry area. Some properties display a drop-down arrow in the property entry area when you click in the area. The drop-down arrow tells you that Access has a list of values from which you can choose. If you click the down arrow in the Control Source property, you find that the drop-down list displays a list of all fields in the example data source — tblProducts. Setting the Control Source property to a field in a table creates a bound control.
Some properties have a list of standard values such as Yes or No; others display varying lists of fields, forms, reports, or macros. The properties of each object are determined by the control itself and what the control is used for.
A nice feature in Access is the ability to cycle through property choices by repeatedly double-clicking the choice. For example, double-clicking the Display When property alternately selects Always, Print Only, and Screen Only.
The Builder button contains an ellipsis (...) and opens one of the many builders in Access — including the Macro Builder, the Expression Builder, and the Code Builder. When you open a builder and make some selections, the property is filled in for you. You’ll learn about builders later in this book.
Each type of object has its own Property window and properties. These include the form itself, each of the form sections, and each of the form’s controls. You display each of the Property windows by clicking the object first or by selecting the object from the Property Sheet’s combo box. The Property window will instantly change to show the properties for the selected object.
You might notice that each of the data fields has a label control and a text box control. Normally, the label’s Caption property is the same as the text box’s Name property. The text box’s Name property is usually the same as the table’s field name — shown in the Control Source property. Sometimes, the label’s Caption is different because a value was entered into the Caption property for each field in the table.
When creating controls on a form, it’s a good idea to use standard naming conventions when setting the control’s Name property. Name each control with a prefix followed by a meaningful name that you’ll recognize later (for example, txtTotalCost, cboState, lblTitle). Table 35.2 shows the naming conventions for form and report controls. You can find a very complete, well-established naming convention online at www.xoc.net/standards.
Prefix | Object |
frb | Bound object frame |
cht | Chart (graph) |
chk | Check box |
cbo | Combo box |
cmd | Command button |
ocx | ActiveX custom control |
det | Detail (section) |
gft[n] | Footer (group section) |
fft | Form footer section |
fhd | Form header section |
ghd[n] | Header (group section) |
hlk | Hyperlink |
img | Image |
lbl | Label |
lin | Line |
lst | List box |
opt | Option button |
grp | Option group |
pge | Page (tab) |
brk | Page break |
pft | Page footer (section) |
phd | Page header (section) |
shp | Rectangle |
rft | Report footer (section) |
rhd | Report header (section) |
sec | Section |
sub | Subform/subreport |
tab | Tab control |
txt | Text box |
tgl | Toggle button |
fru | Unbound object frame |
The properties displayed in Figure 35.27 are the specific properties for the Description text box. The first two properties, Name and Control Source, are set to Description.
The Name is simply the name of the field itself. When a control is bound to a field, Access automatically assigns the Name property to the bound field’s name. Unbound controls are given names such as Field11 or Button13. However, you can give the control any name you want.
With bound controls, the Control Source property is the name of the table field to which the control is bound. In this example, Description refers to the field with the same name in tblProducts. An unbound control has no control source, whereas the control source of a calculated control is the actual expression for the calculation, as in the example =[SalePrice]–[Cost].
Form view is where you actually view and modify data. The data in Form view is the same data shown in a table or query’s Datasheet view, just presented a little differently. Form view presents the data in a user-friendly format, which you create and design. Double-click a form object in the Navigation pane to open the form in Form view.
Figure 35.28 shows the Access window with a newly created form displayed in Form view. This view has many of the same elements as Datasheet view. At the top of the screen, you see the Access title bar, the Quick Access Toolbar, and the Ribbon. The form in the center of the screen displays your data, one record at a time.
The status bar at the bottom of the Access window displays the active field’s Status Bar Text property that you defined when you created the table (or form). If no Status Bar Text exists for a field, Access displays “Form View” in the status bar. Generally, error messages and warnings appear in dialog boxes in the center of the screen (rather than in the status bar). The navigation controls and search box are found at the bottom of the form’s window and the view shortcuts are found in the status bar. These features let you move from record to record, quickly find data, or switch views.
The Home tab of the Ribbon tab (shown in Figure 35.29) provides a way to work with the data. The Home tab has some familiar objects on it, as well as some new ones. This section provides an overview of the Home tab. The individual commands are described in more detail later in this chapter.
At the far left is the Views group, which enables you to switch among the following views, which you can see by clicking the button’s drop-down arrow.
The Clipboard group contains the Cut, Copy, Paste, and Format Paint commands. These commands work like the same commands in other applications (like Word and Excel). The Clipboard is a resource provided by Windows and shared by virtually all Windows applications. Items you copy or cut from Excel, for example, can be pasted into Access if the context is appropriate. For example, you could copy a VBA procedure from an Excel worksheet and paste it into an Access VBA code module because the contexts are the same. But you can’t copy an Excel spreadsheet and paste it into an Access form in Form view, because Form view has no way of working with an Excel spreadsheet.
After you cut or copy a selection in Access, the Paste command’s drop-down arrow gives you three choices:
The Sort & Filter group lets you change the order of the records, and, based on your criteria, limit the records shown on the form.
The Records group lets you save, delete, or add a new record to the form. It also contains commands to show totals, check spelling, freeze and hide columns, and change the row height and cell width while the form is displayed in Datasheet view.
The Find group lets you find and replace data and go to specific records in the datasheet. Use the Select command to select a record or all records.
The Window group contains two commands:
The Text Formatting group lets you change the look of the datasheet in Datasheet view or Design view. Use these commands to change the font, size, bold, italic, color, and so on. Use the Align Left, Align Right, and Align Center commands to justify the data in the selected column. Click the Gridlines option to toggle gridlines on and off. Use Alternate Row Color to change the colors of alternating rows, or make them all the same. When modifying text in a Long Text field with the Text Format property set to Rich Text, you can use these commands to change the fonts, colors, and so on.
Navigating a form is nearly identical to moving around a datasheet. You can easily move around the form by clicking the control that you want and making changes or additions to your data. Because the form window displays only as many fields as can fit onscreen, you need to use various navigational aids to move within your form or between records.
Table 35.3 displays the navigational keys used to move between fields within a form.
Navigational Direction | Keystrokes |
Next field | Tab, Right Arrow key, Down Arrow key, or Enter |
Previous field | Shift+Tab, Left Arrow key, or Up Arrow key |
First field of current record | Home |
First field of first record | Ctrl+Home |
Last field of current record | End |
Last field of last record | Ctrl+End |
Next page | Page Down or Next Record |
Previous page | Page Up or Previous Record |
Although you generally use a form to display one record at a time, you still need to move between records. The easiest way to do this is to use the Navigation buttons, shown in Figure 35.30.
The Navigation buttons are the six controls located at the bottom-left corner of the Form window. The two leftmost controls move you to the first record and the previous record in the form. The three rightmost controls position you on the next record, last record, or new record in the form. If you know the record number (the row number of a specific record), you can click the Current Record box, enter a record number, and press Enter to go directly to that record.
The record number displayed in the Navigation controls is just an indicator of the current record’s position in the recordset and may change when you filter or sort the records. To the right of the record number is the total number of records in the current view. The record count may not be the same as the number of records in the underlying table or query. The record count changes when you filter the data on the form.
Earlier in this book, you learned datasheet techniques to add, change, and delete data within a table. These techniques are the same ones you use on an Access form. Table 35.4 summarizes these techniques.
Editing Technique | Keystrokes |
Move insertion point within a control | Press the Right Arrow and Left Arrow keys |
Insert a value within a control | Select the insertion point and type new data |
Select the entire contents of a control | Press F2 |
Replace an existing value with a new value | Select the entire field and enter a new value |
Replace a value with value of the preceding field | Press Ctrl+’ (single quotation mark) |
Replace the current value with the default value | Press Ctrl+Alt+Spacebar |
Insert the current date into a control | Press Ctrl+; (semicolon) |
Insert the current time into a control | Press Ctrl+: (colon) |
Insert a line break in a Text control | Press Ctrl+Enter |
Insert a new record | Press Ctrl++ (plus sign) |
Delete the current record | Press Ctrl+− (minus sign) |
Save the current record | Press Shift+Enter or move to another record |
Toggle values in a check box or option button | Spacebar |
Undo a change to the current control | Press Esc or click the Undo button |
Undo a change to the current record | Press Esc or click the Undo button a second time after you Undo the current control |
Some controls, including the following, can’t be edited:
Object Linking and Embedding (OLE) objects are objects not part of an Access database. OLE objects commonly include pictures but may be any number of other data types, such as links to Word documents, Excel spreadsheets, and audio files. You can also include video files such as MPG or AVI files.
In Datasheet view, you can’t view a picture or an OLE object without accessing the OLE server (such as Word, Excel, or the Windows Media Player). In Design view, however, you can size the OLE control area to be large enough to display a picture, chart, or other OLE objects in Form view. You can also size text box controls on forms so that you can see the data within the field — you don’t have to zoom in on the value, as you do with a datasheet field.
The Access OLE control supports many types of objects. As with a datasheet, you have two ways to enter OLE fields into a form:
When displaying a picture in an OLE control, set the Size Mode property to control how the image representing the OLE object is displayed. The settings for this property are
The Features field in the form shown in Figure 35.28 is a Long Text data type. This type of field contains up to 1GB of characters. The first three lines of data are visible in the text box. When you click in this text box, a vertical scroll bar appears, allowing you to view all the data in the control.
Better yet, you can resize the control in the form’s Design view if you want to make it larger to show more data. Another method for viewing more text in a Long Text field’s text box is to press Shift+F2 with the text box selected. A Zoom dialog box is displayed, as shown in Figure 35.32, allowing you to see more data. The text in the Zoom dialog box is fully editable. You can add new text or change text already in the control.
The SaleDate field in the frmSales_Layout form shown next in Figure 35.33 is a Date/Time data type. This field is formatted to accept and show date values. When you click in a Date/Time field on a form, a Date Picker icon automatically appears next to it, as shown in Figure 35.33. Click the Date Picker to display a calendar from which you can choose a date.
If the Date Picker doesn’t appear, switch to Design view and change the control’s Show Date Picker property to For Dates. Set the Show Date Picker property to Never if you don’t want to use the Date Picker.
Option groups let you choose from a number of option buttons (sometimes called radio buttons). Option buttons let you select one value while deselecting all the other values. Option groups work best when you have a small number of mutually exclusive choices to select from. Figure 35.34 shows an option group labeled Contact Type next to the Follow-Up Date text box. Option groups also work with toggle buttons and check boxes.
The easiest and most efficient way to create option groups is with the Option Group Wizard. You can use it to create option groups with multiple option buttons, toggle buttons, or check boxes. When you’re through, all your control’s property settings are correctly set. To create an option group, switch to Design view and select the Option Group button from the Design tab’s Controls group. Make sure the Use Control Wizards command is selected.
Access has two types of controls — list boxes and combo boxes — for showing lists of data from which a user can select. The list box always displays as much of the list as possible, whereas the combo box has to be clicked to open the list. Also, the combo box enables you to enter a value that is not on the list and takes up less room on the form.
Because combo boxes are very efficient use of space on the surface of a form, you may want to use (for example) a combo box containing values from a table with customer or vendor names, as shown in Figure 35.35. The easiest way to do this is with the Combo Box Wizard. This wizard walks you through the steps of creating a combo box that looks up values in another table. To create a combo box, switch to Design view and select the Combo Box command from the Design tab’s Controls group. Make sure the Use Control Wizards command is selected.
After you create the combo box, examine the Row Source Type, Row Source, Column Count, Column Heads, Column Widths, Bound Column, List Rows, and List Width properties. Once you become familiar with setting these properties, you can right-click a text box, choose Change To ⇒ Combo Box, and set the combo box’s properties manually.
With a form open, switch to Datasheet view by using one of these methods:
The datasheet is displayed with the cursor on the same field and record that it occupied while in the form. Moving to another record and field and then redisplaying the form in Form view causes the form to appear with the cursor on the field occupied in Datasheet view.
To return to Form view — or any other view — select the desired view from the Views group, the View Shortcuts, or the pop-up menu.
Access automatically saves each record when you move off it. Pressing Shift+Enter or selecting Save from the Records group on the Ribbon saves a record without moving off it. Closing the form also saves a record.
You can print one or more records in your form exactly as they appear onscreen. (You learn how to produce formatted reports in Chapter 37.) The simplest way to print is to use the keyboard shortcut Ctrl+P to show the Print dialog box. The Print dialog box has several options to customize your printout:
You can also click the Properties button and set options for the selected printer or select a different printer. The Setup button allows you to set margins and print headings.
Printing a form is like printing anything else. Windows is a WYSIWYG (“What You See Is What You Get”) environment, so what you see on the form is what you get in the printed hard copy. If you added page headers or page footers, they would be printed at the top or bottom of the page. The printout contains any formatting that you specified in the form (including lines, boxes, and shading) and converts colors to grayscale if you’re using a black-and-white printer.
The printout includes as many pages as necessary to print all the data. If your form is wider than a single printer page, you need multiple pages to print your form. Access breaks up the printout as necessary to fit on each page.
The Print command under the File menu provides additional printing options:
In this chapter, you learned how to add different types of forms to your database using the Create tab’s Form group. At this point, you should be able to: