In Chapter 7, you learned about the tools necessary to create and display a form—Design View, bound and unbound controls, the Field List, and the ribbon’s Controls group. In this chapter, you learn how to work with data on the form, view and change the form’s properties, and use Access’s new Layout View.
In this chapter, you use tblProducts in the Chapter08.accdb database to provide the data necessary to create the examples used in this chapter.
Form View is where you actually view and modify data. Working with data in Form View is similar to working with data in a table or query’s Datasheet View. Form View presents the data in a user-friendly format, which you create and design.
For more information on working in Datasheet View, see Chapter 6.
To demonstrate the use of the Form View, follow these steps to create a new form based on tblProducts:
1. Select tblProducts in the Navigation Pane.
2. Click the Create tab on the ribbon.
3. Click on the Form command in the Form group.
4. Click the Form View button on the Home tab’s Views group to switch from Layout View to Form View.
Figure 8-1 shows the Access window with the 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, Quick Access toolbar, and the ribbon. The form in the center of the screen displays your data, one record at a time.
If the form contains more fields than can fit on-screen at one time, Access 2007 automatically displays a horizontal and/or vertical scroll bar that can be used to see the remainder of the data. You can also see the rest of the data by pressing the PgDn key. If you’re at the bottom of a form, or the entire form fits on the screen, and press PgDn, you’ll move to the next record.
The status bar at the bottom of the window displays the active field’s Field Description that you defined when you created the table (or form). If no Field Description exists for a specific field, Access displays the words Form View. Generally, error messages and warnings appear in dialog boxes in the center of the screen (rather than in the status bar). The navigation buttons, search box, and view shortcuts are found at the bottom of the screen. These features lets you move quickly from record to record, find data quickly, or switch views.
Figure 8-1
The Form ribbon (shown in Figure 8-2) 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 form’s Home tab; the individual commands will be described in more detail later in this chapter.
Figure 8-2
The first group is the View group, which allows you to switch between Form View, Datasheet View, PivotTable View, PivotChart View, Layout View, and Design View. You can see all six choices by clicking the command’s down-arrow. Clicking Form View lets you manipulate data on the form. Datasheet View shows the data in a row-and-column format. Design View permits you to make changes to the form’s design. Layout View lets you change the form’s design while viewing data. PivotTable View and PivotChart View let you create PivotTables and PivotCharts based on the form’s data. All these commands may not be available on all forms. By setting the form’s properties, you can limit which views are available. You’ll learn more about form properties later in this chapter.
The Clipboard group contains the Cut, Copy, and Paste commands. These commands work like the commands in other applications (Word, Excel, and so on). The Paste command’s down arrow gives you three choices: Paste, Paste Special, and Paste Append. Paste Special gives you the option of pasting the contents of the Clipboard in different formats (Text, CSV, Records, etc.) Paste Append pastes the contents of the Clipboard as a new record—provided a record with a similar structure was copied.
The Font group lets you change the look of the datasheet in Datasheet 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 command to toggle gridlines on and off. Use the Alternate Fill/Back Color command to change the colors of alternating rows, or make them all the same. When modifying text in a memo field with the Text Format property set to Rich Text, you can use these commands to change the fonts, colors, and so on.
The Rich Text group lets you change a memo field’s data if the field’s Text Format property is set to Rich Text. Use these commands to add bullets or numbered lists and change the indentation levels.
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 in Datasheet View.
The Sort & Filter group lets you change the order of the records, as well as limit the records being displayed—based on criteria you want.
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.
Navigating a form is nearly identical to navigating a datasheet. You can easily move around the form window by clicking the field that you want and making changes or additions to your data. Because the form window displays only as many fields as can fit on-screen, you need to use various navigational aids to move within your form or between records.
Table 8-1 displays the navigational keys used to move between fields within a form.
If you have a form with more than one page, a vertical scroll bar displays. You can use the scroll bar to move to different pages on the form. You can also use the PgUp and PgDn keys to move between form pages. You can move up or down one field at a time by clicking the scroll-bar arrows. With the scroll-bar button, you can move past many fields at once.
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, as shown in Figure 8-3. The Navigation buttons let you move to the desired record.
The Navigation buttons (shown in Figure 8-3) are the six controls located at the bottom of the Form window, which you click to move between records. The two leftmost controls move you to the first record or 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 Record Number box, enter a record number, and press Enter.
Figure 8-3
The record number between the Navigation buttons is a virtual record number. The number is not attached to any specific record—it’s just an indicator as to the record number you’re on given the current filter or sort. It will change with each time you filter or sort the records. The number to the right of the record number displays the number of records in the current view. The number of records displayed might not be the total number of records in the underlying table or query; this number changes when you filter the data on the form.
You can also press PgDn to move to the current field in the next record, or PgUp to move to the current field in the preceding record.
Earlier in the book, you learned techniques to add, change, and delete data within a table by using a datasheet. These techniques are the same ones you use within a form. Table 8-2 summarizes these techniques.
Some controls can’t be edited, such as:
• Controls displaying AutoNumber fields: Access maintains AutoNumber fields automatically, calculating the values as you create each new record.
• Calculated controls: Access uses calculated control in forms or queries; these values are not actually stored in your table.
• Locked or disabled fields: You can set certain properties to prevent editing for specific controls.
• Controls in multiuser locked records: If another user locks the record, you can’t edit any controls in that record.
OLE (Object Linking and Embedding) objects are objects not part of an Access database. These commonly include pictures but an OLE field can also contain links to objects such as Word documents, Excel spreadsheets, and audio files such as .mp3, .wav, or .wmv files. You can also include video files such as .mpg or .avi files.
In Datasheet View, you can’t view a picture or any OLE object without accessing the OLE server (such as Word, Excel, or the Microsoft Media Player). In Form View, however, you can size the OLE control area to be large enough to display a picture, business graph, or any visual OLE object. 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.
Any object supported by an OLE server can be stored in an Access OLE field. OLE objects are entered into a form so that you can see, hear, or use the value. As with a datasheet, you have two ways to enter OLE fields into a form:
• Paste them in from the commands in the ribbon’s Clipboard group.
• Right-click on the OLE field and click Insert Object from the pop-up menu to display the Insert Object dialog box, shown in Figure 8-4.
Figure 8-4
Use the Insert Object dialog box to add a new object to the OLE field, or add an object from an existing file. Choose the Create from File option button to add a picture or other OLE object from a file that already exists.
When displaying a picture in an OLE control, set the Size Mode property to control how the picture is displayed. The settings for this property are:
• Clip: Keeps the picture at its original size and truncates any portion of the picture that doesn’t fit in the control.
• Zoom: Fits the picture in the control and keeps it in its original proportion, which may result in extra white space.
• Stretch: Sizes picture to fit exactly between the frame borders; this setting may distort the picture.
The Features field in the form shown in Figure 8-1 is a Memo data type. This type of field allows up to 65,535 bytes of text for each field. The first two sentences of data appear in the text box. When you click in this text box, a vertical scroll bar appears. Using this scrollbar, you can view the rest of the data in the control.
Better yet, you can resize the Memo control in the form’s Design View if you want to make it larger to see more data. You can also press Shift+F2 and display a Zoom dialog box, as shown in Figure 8-5, which lets you see more data.
Figure 8-5
The AuctionEndDate field in the form shown in Figure 8-5 is a Date/Time data type. This field is formatted to accept and show date values. When you click in this text box, a Date Picker icon appears next to it, as shown in Figure 8-6. 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.
Figure 8-6
Option groups let you choose values from option buttons (sometimes called radio buttons). Option buttons let you select one value while deselecting the previous value. Option groups work best when you have a small number of choices to select from. Figure 8-7 shows an option group next to the Auction check box; both controls perform the same operation.
Figure 8-7
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. This wizard greatly simplifies the process and enables you to create an option group quickly. To create an option group, switch to Design View and select the Option Group command from the Design tab’s Controls group. Make sure the Use Control Wizards command is selected.
Option groups can only be bound to numeric fields. When creating an option group for a Yes/No field (which is numeric), set the Yes value to –1 and the No value to 0.
Access has two types of controls—list boxes and combo boxes—that enable you to show lists of data from which a user can select. The list box is always open and ready for selection, whereas the combo box has to be clicked to open the list for selection. Also the combo box enables you to enter a value that is not on the list and takes up less room on the form.
You may want to replace the Category text box with a combo box containing values from tblCategories, as shown in Figure 8-8. 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.
Figure 8-8
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, select Change To⇒Combo Box, and set the combo box’s properties manually.
While in the form, you can display a Datasheet View of your data by using one of the following methods:
• Click the Datasheet View command in the Home tab’s Views group.
• Click the Datasheet View button in the View Shortcuts section at the bottom-right of the Access window.
• Right-click on the form’s title bar—or any blank area of the form—and choose Datasheet View from the pop-up menu.
The datasheet is displayed with the cursor on the same field and record that it occupied in the form. If you move to another record and field and then redisplay the form, the form appears with the cursor on the field and with the record it last occupied in the datasheet.
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 saves each record when you move off it. Pressing Shift+Enter or selecting Save from the ribbon’s Records group 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 on-screen. (You learn how to produce formatted reports in Chapter 9.) The simplest way to print is to click the Print icon in the Quick Access toolbar. This prints the form to the Windows default printer. Click on the Microsoft Office Button to view other print options.
Printing a form is like printing anything else; you’re in a WYSIWYG (“What You See Is What You Get”) environment, so what you see on the form is essentially what you get in the printed hard copy. If you added page headers or page footers, they’re 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 monochrome 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.
You can also control printing from the Print dialog box, which you open by clicking the Microsoft Office Button, and then clicking on Print. From this dialog box, customize your printout by selecting from several options:
• Print Range: Prints the entire form or only selected pages or records
• Copies: Determines the number of copies to be printed
• Collate: Determines whether multiple copies are collated
You can also click the Properties button and set options for the selected printer or select the printer itself to change the type of printer. The Setup button allows you to set margins and print headings.
Although you may have all the information in the form ready to print, but you aren’t sure whether that information will print on multiple pages or fit on one printed page. To preview your print job, click the Print Preview command under the Print menu to display the Print Preview window. The default view is the first page in single-page preview. Use the ribbon commands to select different views and zoom in and out. Click Print to print the form to the printer. Click the Close Print Preview command on the right side of the ribbon to return to Form View.
You use form properties to change the way the entire form is displayed. This includes properties such as the form’s background color or picture, the form’s width, and so on. Tables 8-3 through 8-5 later in this chapter discuss some of the more important properties. Changing default properties is relatively easy: You select the property in the Property Sheet and set a new value. Following are some of the more important form properties that you may want to be aware of and may want to set.
The form selector is the area where the rulers meet; a small black square appears when the form is selected, as shown in Figure 8-9.
Figure 8-9
To set a form’s properties, you have to show the Property Sheet for the form. Switch to Design View and use one of the following methods to display the form’s Property Sheet:
• Click the form selector so a small black square appears, then click the Property Sheet command in the Design tab’s Tools group.
• Click the Property Sheet command in the Design tab’s Tools group, then select Form from the drop-down at the top of the Property Sheet.
• Double-click the form selector.
• Right-click the form selector and select Properties from the pop-up menu.
The form’s Property Sheet appears docked to the right-side of the Access window. Because the Property Sheet is a window, it can be undocked, moved, and resized. It does not, however, have Maximize or Minimize buttons.
For more information on working with the Property Sheet, see Chapter 7.
Normally, the title bar displays the name of the form after it is saved. By changing the Caption property, you can display a different title on the title bar when the form is in Form View. To change the title bar text, follow these steps:
1. Click the form selector to make sure the form itself is selected.
2. Click the Property Sheet command in the Design tab’s Tools group.
3. Click the Caption property in the Property Sheet.
4. Type Products, as shown in Figure 8-10.
5. Click any other property or press Enter.
Figure 8-10
Switch to Form View to see the form’s new title bar text. The caption you enter in the form’s properties overrides the name of the saved form.
A bound form is one that places data into a table when the record is saved. Forms can be bound or unbound. To create a bound form, you must specify a data source in the form’s Record Source property. In Figure 8-10, you can see the form’s Property Sheet where the very first property is Record Source. If you want your form bound to a data source, this is where the name of the data source goes. Figure 8-10 shows the Record Source property set to tblProducts.
The data source can be on of three choices:
• Table: The name of a table from the current database file. The table can be a local table (stored in the database itself) or it can be linked to another Access database or an outside data source such as SQL Server.
• Query: The name of a query that references one or more tables from the current database file.
• SQL Statement: A SQL SELECT Statement that contains the name of a table or query.
If a form is unbound—the Record Source property is blank—you can’t have any bound controls on the form (bound controls have their Control Source property set to a field in a table). If you add fields from the Field List and the Record Source property is blank, Access will set the Record Source property based on the fields you add.
For more information on adding bound controls with the Field List, see Chapter 7.
Access 2007 uses several properties to determine how a form is viewed. The most common one is the Default View. The Default View property determines how the data is displayed when the form is first opened in Form View. There are six choices:
• Single Form: Displays one record at a time
• Continuous Forms: Shows more than one record at a time
• Datasheet: Row and column view like a spreadsheet or the standard query Datasheet View
• PivotTable: A datasheet with movable columns that can be swapped with rows
• PivotChart: A graph made from a PivotTable
• Split Form: A new feature in Access 2007 that gives you two views of the data at the same time, letting you select a record from a datasheet in the upper section and edit the information in a form in the lower section
Single Form is the default and displays one record per form page, regardless of the form’s size. Continuous Forms tells Access to display as many detail records as will fit on-screen. Normally, you would use this setting to define the height of a very small form and to display many records at one time. Figure 8-11 shows such a continuous form with many records. The records have a small enough height that you can see a number of them at once.
Figure 8-11
In Figure 8-11, you can see the form’s Property Sheet with the choices for the Default View property.
A PivotTable form can display a field’s values horizontally or vertically and then calculate the total of the row or column. Similar to this is the PivotChart, which displays a graphical analysis of data stored in a table, query, or form.
There are five separate properties to allow the developer to determine if the user can change the default view. These include Allow Form View, Allow Datasheet View, Allow PivotTable View, Allow PivotChart View, and Allow Layout View. The default settings are Yes to all of these properties, which lets you switch between Form View and Datasheet View, as well as PivotTable View and PivotChart View. If you set the Allow Datasheet View property to No, the Datasheet View commands (in the ribbon’s Views group, the form’s View Shortcuts, and right-click pop-up menu) won’t be available; the data can be viewed only as a form. If you set the Allow Form View property to No, the Form View commands won’t be available; the data can be viewed only as a datasheet.
The Record Selectors property determines whether the Record Selector bar (the vertical bar shown in Figure 8-1 on the left side of a form with a right-pointing arrow indicating the selected record) is displayed. The Record Selector bar is very important in multiple-record forms or datasheets because it’s highlighted to indicate the current record and a pencil indicates that the record is being edited. Though the Record Selector bar is important for datasheets, you probably won’t want it for a single record form. To eliminate it, simply change the form’s Record Selectors property from Yes to No.
Set the Record Selectors property to No for your form.
Tables 8-3 through 8-5 list the most commonly used form properties and offers brief descriptions of each. You will learn more about many of these when they are used in examples throughout the chapters. Event properties are covered in Part II.
Although the form’s Detail section usually contains the majority of the controls that display data, there are other optional sections in a form that you can add:
• Form Header: Displayed at the top of each page when viewed and at the top when the form is printed.
• Page Header: Displayed only when the form is printed; prints after the form header.
• Page Footer: Appears only when the form is printed; prints before the form footer.
• Form Footer: Displayed at the bottom of each page when viewed and at the bottom of the form when the form is printed.
A Form Header appears at the top of the form, while a Form Footer appears at the bottom. The Form Header and Footer remain on the screen, while any controls in the Detail section can scroll up and down.
Page Headers and Page Footers are displayed only if the form is printed. They do not appear when the form is displayed.
You can select the Form Header/Footer or Page Header/Footer commands from the Arrange tab’s Show/Hide group in the form’s Design View. These commands will place a Form Header/Footer or Page Header/Footer on the form.
In this section, you’ll learn how to change a form’s layout using Access’s new Layout View. You’ll add, move, and resize controls, as well as change a few other characteristics while viewing the form’s data.
In the Home tab’s Views group, click the Layout View command to switch to Layout View. Click on the ribbon’s Arrange tab (shown in Figure 8-12) to show commands available to change the form while viewing data.
Figure 8-12
In previous versions of Access, you had to make changes to the form in Design View. In Layout View, you can change these properties while looking at the data instead of the Control Source. Click the Property Sheet command in the Arrange tab’s Tools group to display the Property Sheet for a selected Control.
For more information on changing control properties with the Property Sheet, see Chapter 7.
If you move controls around or add a new control in between existing controls, you may notice that when you use Tab to move from control to control, the cursor jumps around the screen, skipping some control and moving fairly randomly around the screen. This route may seem strange, but that is the original order in which the controls were added to the form.
The tab order of the form is the order in which you move from control to control when you press Tab. The form’s default tab order is always the order in which the controls were added to the form. If you move the controls around or even delete one control and re-add it for any reason, you’ll probably need to change the tab order. Even though you may make heavy use of the mouse when designing your forms, the average data-entry person still uses the keyboard to move from control to control.
When you need to change the tab order of a form, select the Tab Order command from the Arrange tab’s Control Layout group to display the Tab Order dialog box, shown in Figure 8-13. This dialog box shows the controls in the form that you can tab to; controls such as labels, lines, and other non-data controls don’t appear.
Figure 8-13
The Tab Order dialog box lets you select either one row or multiple rows at a time. Multiple contiguous rows are selected by clicking the first Selection bar and dragging down to select multiple rows. After the rows are highlighted, the selected rows can be dragged to their new positions.
The Tab Order dialog box has several buttons at the bottom of the window. The Auto Order button places the controls in order from left to right and from top to bottom, according to their position in the form. This button is a good place to start when you have significantly rearranged the controls. The OK button applies the changes to the form; the Cancel button closes the dialog box without changing the tab order.
Each control has two properties related to the Tab Order dialog box. The Tab Stop property determines whether pressing the Tab key lands you on the control. The default is Yes; changing the Tab Stop property to No removes the control from the tab order. When you set the tab order, you are setting the Tab Index property values. Moving the fields around in the Tab Order dialog box changes the Tab Index properties of those (and other) controls.
You may want to move several controls so that they are all aligned (lined up). The Layout ribbon’s Control Alignment group has several options for aligning controls: Left, Right, Top, and Bottom. These commands work the same as the Control Alignment commands described in Chapter 7, with the exception of aligning controls to the grid, which isn’t available in Layout View.
To modify the formatting of text within a control, select the control by clicking it, then select a formatting style to apply to the control. The Layout View ribbon’s Design tab—shown in Figure 8-14—contains additional commands for changing the format of a control.
Figure 8-14
To change the fonts for the Category control, make sure you’re in Layout View, then follow these steps:
1. Select the Category control by clicking on it.
2. Change the Font Size to 14, and then click on the Bold button in the Design tab’s Font group.
You probably can only see a portion of the label. The label control now needs to be resized to display all the text.
The Field List displays a list of fields from table or query the form is based on. You add bound controls to the form by dragging fields from the Field List onto the form. Select and drag them one at a time, or select multiple fields by using the Ctrl key or Shift key. The Field List in Layout View works the same as the Field List in Design View, which is described in detail in Chapter 7.
Click the Add Existing Fields command in the Design tab’s Controls group to display the Field List. By default, the Field List appears docked on the right of the Access window, shown in Figure 8-15. This window is movable and resizable and displays a vertical scrollbar if it contains more fields than can fit in the window.
To add fields from the Field List to a new form, follow these steps:
1. Select tblProducts in the Navigation Pane.
2. Click the Create tab on the ribbon, and then click on the Blank Form command in the Form group to display a new form in Layout View.
3. If the Field List isn’t displayed, click on the ribbon’s Design tab, and then click the Add Existing Fields command from the Controls group.
4. Click the ProductID field in the Field List.
5. Hold the Shift key and click the Cost field in the Field List.
6. Drag the selected fields from the Field List to the Form, as shown in Figure 8-15.
Figure 8-15
You can select noncontiguous fields in the list by clicking each field while holding down the Ctrl key. Each highlighted field can be dragged (as part of the group) to the form’s Layout View.
A calculated control displays a value that isn’t stored in the form’s underlying Record Source. To understand creation of a calculated control, you will now create one as follows:
1. Select tblProducts in the Navigation Pane.
2. Click the Create tab on the ribbon, then click on the Blank Form command in the Form group to display a new form in Layout View.
3. Drag the Cost and SalePrice fields from the Field List onto the form.
4. Switch the form to Design View.
5. Click on the Text Box command in the Controls group and draw it on the form.
6. Set the Name property to txtProfit.
The txt prefix means the control is a text box.
7. Set the Control Source property to =[SalePrice]-[Cost].
8. Change the Format property to Currency.
9. Change the Decimal Places property to 2.
10. Change the label’s Caption property to Profit:.
11. Switch to Form View to test the calculation.
Your screen should look like one shown in Figure 8-16. The txtProfit control shows the difference between the SalePrice and Cost.
Figure 8-16
By opening a form in Design View, clicking the Microsoft Office Button, and selecting Save As, you can save a form as a report. The entire form is placed in the report. If the form has form headers or footers, these are placed in the Report Header and Report Footer sections. If the form has page headers or page footers, these are placed in the Page Header and Page Footer sections in the report. After the design is in the Report Design window, it can be enhanced using the report design features. This allows you to add group sections and additional totaling in a report without having to re-create a great layout. You’ll learn more about reports in later chapters.
In this chapter, you learned that working with data in Form View is similar to working with data in a table or query’s Datasheet View. You learned how to navigate between fields and records and how to use controls such as option groups and combo boxes to facilitate data entry.
You also learned about a form’s properties, including the different groupings and each property setting. You learned how setting some of these properties affects a form’s appearance. You added a form header and footer and worked with the new Layout View, which lets you manipulate a form and its controls while viewing live data.