Now that you understand the basic mechanics of form design, you could continue to build all your forms from scratch in Design view. However, even the most experienced developers take advantage of the many wizards built into Access 2007 to get a jumpstart on design tasks. This section shows you how to use quick create form commands and the Form Wizard to quickly build a custom form.
Access 2007 introduces new quick create commands so that you can create new forms with one click on a Ribbon command. As you’ll learn in this section, you can build forms designed in a variety of different views, so you can pick the style you need for the data-editing task at hand. You just walked through creating a form from scratch, so you should recall how much time it took to place all the fields on the form design grid, resize and move some of the controls, and change some of the form properties. The quick create commands can do a lot of the heavy work in designing a base form, which you can then modify to meet your specific needs.
Suppose you want to create a data entry form for the tblProducts table in the Conrad Systems Contacts database. Begin by opening the ContactsDataCopy.accdb database and click the top of the Navigation Pane to open the Navigation Pane menu. Click Object Type under Navigate To Category and Tables under Filter By Group to display a list of only the tables in this database. Select the tblProducts table in the Navigation Pane and then click the Form command in the Forms group on the Create tab. Access immediately creates a new single form based on the tblProducts table, including a control for every field in that table, and displays it in Layout view as shown in Figure 11–23.
Figure 11–23: Access can save you time by creating a single form using all the fields in the selected table.
As you can see, Access creates this form very quickly, and it looks professional. Switch to Design view for this form by clicking the arrow below the View button in the Views group on the Home tab and clicking Design View. Notice how Access creates a text box on the form for each field in the tblProducts table and an associated label for each text box with a caption, and aligns all the controls. Access also creates a bitmap picture logo and a label for the form’s title in the Header section.
This form could still use some modification, such as entering a different form title and resizing some controls, but overall Access has completed a lot of the hard work of creating the form. Close this form, and do not save it.
Select the tblProducts table again in the Navigation Pane and then click the Split Form command in the Forms group on the Create tab. Access immediately creates a new split form containing every field in the tblProducts table and displays it in Layout view as shown in Figure 11–24.
Figure 11–24: When you click the Split Form command, Access creates a new split form based on your table.
Here again Access creates controls and associated labels for all the fields in the tblProducts table. Switch to Design view by clicking the arrow in the Views group and clicking Design View. The form’s Default View property is set to Split Form, and the Split Form Orientation property is set to Datasheet On Bottom. The top of the Form window displays the fields from the tblProducts table in Single Form view, and the bottom of the form displays all the records from the tblProducts table in Datasheet view. Close this form now, and do not save it when prompted.
Select the tblProducts table again in the Navigation Pane and then click the Multiple Items command in the Forms group on the Create tab. Access immediately creates a new continuous form based on all the fields in the tblProducts table and displays it in Layout view as shown in Figure 11–25.
Figure 11–25: Use the Multiple Items command to create a continuous form.
In this continuous form, Access creates controls for all the fields in the tblProducts table horizontally across the Form window. Switch to Design view by clicking the arrow in the Views group and clicking Design View. The form’s properties have been set to display the products in Continuous Form view, which means you can view more than one record at a time. Notice that Access places the associated label for each control in the form’s Header section. Close this form now, and do not save it when prompted.
Select the tblProducts table again in the Navigation Pane, click the More Forms command in the Forms group on the Create tab, and then click the Datasheet command. Access immediately creates a new form in Datasheet view using all the fields in the tblProducts table and displays it as shown in Figure 11–26.
Figure 11–26: This datasheet form was created using the Datasheet command on the More Forms menu.
Switch to Design view by clicking the arrow in the Views group and clicking Design View. The form’s properties have been set to display the products in Datasheet view, which means you can view more than one record at a time and all the records are stacked close together like a table datasheet. In datasheet forms, Access places a column header with the name that normally appears for an associated label for each control. Close this form now, and do not save it when prompted.
Access 2007 also has quick create commands for PivotChart and PivotTable views in the Forms group. You can use these commands to get a jump-start on creating PivotChart and PivotTable forms. You’ll learn more about creating and using PivotChart forms in Chapter 13.
The quick create form commands are easy to use, but you have no flexibility on how Access initially creates the form. The Form Wizard is another tool you can use to quickly create forms in your database. Begin by opening the ContactsDataCopy.accdb database, and click the top of the Navigation Pane to display the Navigation Pane menu. Select Object Type under Navigate To Category and Tables under Filter By Group to display a list of only the tables in this database. Select the tblProducts table in the Navigation Pane, click the More Forms command in the Forms group on the Create tab, and then click the Form Wizard command. Access opens the first page of the Form Wizard, as shown in Figure 11–27.
Figure 11–27: The first page of the Form Wizard displays fields you can select to include in your form.
You can select any field in the Available Fields list and click the single right arrow (>) button to copy that field to the Selected Fields list. You can also click the double right arrow (>>) button to copy all available fields to the Selected Fields list. If you copy a field in error, you can select the field in the Selected Fields list and click the single left arrow (<) button to remove the field from the list. You can remove all fields and start over by clicking the double left arrow (<<) button. For this example, click the double right arrow button to use all the fields in the tblProducts table in the new form.
As you’ll learn in Chapter 13, you can select fields from one table or query and then change the data source name in the Tables/Queries combo box to select a different but related table or query. If you have defined the relationships between tables in your database, the Form Wizard can determine how the data from multiple sources is related and can offer to build either a simple form to display all the data or a more complex one that shows some of the data in the main part of the form with related data displayed in an embedded subform. You’ll use this technique to build a more complex form in Chapter 13.
At any time, you can click the Finish button to go directly to the last step of the wizard. You can also click the Cancel button at any time to stop creating the form.
After you select all the fields from the tblProducts table, click Next. On the next page, the wizard gives you choices for the layout of your form. You can choose to display the controls on your form in columns, arrange the controls across the form in a tabular format (this creates a continuous form), create a form that opens in Datasheet view, or place the fields in a block “justified” view. For this example, select Columnar, and then click Next.
The wizard next displays a page on which you can select a style for your form, as shown in Figure 11–28. Note that if you choose to display the form in Datasheet view, the style won’t apply to the datasheet but will appear if you shift from Datasheet view to Form view. The nice thing about this page is that the wizard shows you a sample of each selection on the left side of the page. You can look at each one and decide which you like best. In this example, the Solstice style is selected. In Chapter 12, you’ll learn how to use the AutoFormat facility to create a custom look for your forms.
Figure 11–28: You can select a style for your form on the third page of the Form Wizard.
When you select a style in the Form Wizard, the new style becomes the default for new forms you create using the wizard until you change the style setting again, either in the Form Wizard or with the AutoFormat commands. We’ll discuss AutoFormat in the next chapter.
Click Next to display the final page, where the Form Wizard asks for a title for your form. Type an appropriate title, such as Products. The wizard places this title in the Caption property of the form and also saves the form with this name. (If you already have a form named Products, Access appends a number to the end of the name to create a unique name.) Select the Open The Form To View Or Enter Information option, and then click the Finish button to go directly to Form view. Or you can select the Modify The Form’s Design option, and then click Finish to open the new form in Design view. The finished form is shown in Form view in Figure 11–29.
Figure 11–29: The Form Wizard creates a form in a columnar format using the Solstice style that is very similar to the form produced with the quick create commands.
In the initial release of Access 2007, the Form Wizard failed to apply the background image specified for the style you select when you ask for a Columnar, Datasheet, or Justified form. Microsoft intends to fix this bug in the first service pack. If you do not see the background image, you can reapply the style to your form using AutoFormat. You can read more about AutoFormat in the next chapter. The figures that follow all show the background image applied.
Notice that the Solstice style uses labels sized alike with no ending colons on the captions. Also notice that all the fields in this style are left-aligned, regardless of data type. You’ll learn more about working with styles in the next chapter.
If you’re curious to see the tabular format, you can start a new form on the tblProducts table and use the Form Wizard again. Select all the fields on the first page of the Form Wizard, select Tabular for the layout, and set the style to Northwind. For a title, type Products-Tabular, and open the new form in Form view. It should look something like the form shown in Figure 11–30. Close this form when you finish looking at it.
We modified the form you see in Figure 11–30 to preserve the default sunken effect for text box controls in the Northwind style. If you create this form on a Windows XP or Windows Vista system, choose Use Windows-Themed Controls On Forms in the Current Database category of the Access Options dialog box, and choose the default Windows XP theme in the Display Properties window in Windows XP, or choose the Windows Vista Basic color scheme in Appearance Settings in Windows Vista, the text boxes appear flat on your form.
Figure 11–30: This Products form is in a tabular format using the Northwind style.
You can also investigate what a justified form looks like by going through the exercise again and selecting Justified for the layout on the second page in the Form Wizard. If you choose the Office style and name the form Products-Justified your result should look something like the one shown in Figure 11–31. Close this form when you finish looking at it.
Figure 11–31: This is the Products form in a justified format using the Office style.
The Form Wizard took care of some of the work, but there’s still a lot you can do to improve the appearance and usability of this form. And even though the Form Wizard adjusted the display control widths, they’re still not perfect. Most of the text boxes are larger than they need to be. The Form Wizard created a two-line text box for product name when one should suffice. We personally prefer to see field labels right-aligned and bold so that they’re easier to read. Finally, the ProductID field is an AutoNumber data type, so you should probably lock it and disable it so the user cannot type in the field.
You can either start with the columnar format form using the Solstice style (shown in Figure 11–29) or start a new form with the None style. (We decided to modify the Solstice style form from Figure 11–29 for the following examples.) Open the form in Design view. To help align controls, click outside the Detail section so that the form is selected and make sure that the Grid X and Grid Y properties in the form’s property sheet are set to 24. (Leave the settings at Grid X=5. and Grid Y=5. if you’re working in metric measurements.) Be sure the Show Grid command is selected in the Show/Hide group on the Arrange contextual tab.
Begin by selecting the ProductID text box and change the Enabled property to No and the Locked property to Yes as you learned to do earlier. We will leave the Special Effect property of this text box set to Flat to give your users a visual clue that they won’t be able to type in the ProductID text box.
The Product ID field does not need to be as wide as it is, so click that control to select it and then click and drag the right edge of the text box control to the left. After the control is about 1. inch wide, release the mouse button and notice that Access resizes all the text box controls to the same width. The Form Wizard has applied a control layout so that all the controls will move and resize together. You can tell whether Access has applied a control layout to the controls by the small box with a crosshair inside just to the left of and slightly above the Product ID label, as shown in Figure 11–32. We discuss control layouts in more detail in the next chapter.
Figure 11–32: If you or Access has applied a control layout to the form controls, a box with a crosshair appears next to the controls.
To make individual size adjustments to the labels and text box controls, you need to highlight all the controls and turn off this control layout. Start by clicking the horizontal ruler just above the left edge of the label controls, and then drag in the ruler toward the right until the selection indicator touches all the labels and text box controls. (If you can’t see the rulers, be sure that you have clicked the Ruler command in the Show/Hide group on the Arrange tab.) Release the mouse button to select all the controls and labels on the form grid, and then click the Remove button in the Control Layout group on the Arrange tab, as shown in Figure 11–32.
Now that you have removed any control layouts, you can continue making adjustments to the individual controls. The ProductName text box needs to be about 3 inches wide. You can set a specific width by clicking the control, opening the property sheet, clicking the Format tab, and typing y in the Width property (the fifth property down the list). The Form Wizard created a text box that is two lines high for ProductName, but it doesn’t need to be bigger than one line. Select the control, and then grab the bottom sizing box in the middle of the control and drag it up to make the control smaller. Click the Size To Fit command in the Size group on the Arrange tab to resize the control to display one line. Click the Format tab in the property sheet and change the Scroll Bars property to None-the Form Wizard specified a vertical scroll bar in the two-line control that it designed. It doesn’t make sense to show a scroll bar in a one-line control that is already wide enough to display all the data. Select the ProductName label, and then grab the bottom sizing box in the middle of the control and drag it up to make it the same height as the ProductName text box.
Now that you’ve made the ProductName text box and associated label smaller, you have extra space between it and the CategoryDescription text box. Select the CategoryDescription, UnitPrice, TrialVersion, TrialExpire, and PreRequisite text boxes and move them up close to the ProductName text box. Unless you turned off Snap To Grid in the Control Layout group on the Arrange tab, it should be easy to line up the controls in their new positions. As you move these four controls, their associated labels will stay aligned with the text boxes.
Next, fix all the labels. Click in the horizontal ruler above the column of labels to select them all. (Access selects the Products label in the form header during this procedure as well, so hold down the Shift key and click the label in the form header to clear it.) Click the Align Right and Bold buttons in the Font group on the Design contextual tab to change the appearance of the labels. Click the Products label in the form header and then click the Italic button in the Font group to add emphasis. Finally, click the Size To Fit command in the Size group on the Arrange tab to make the Product label shrink in size around the text. After you shrink the right margin of your form, move all the controls up closer to the form header and left side of the form grid, and shrink the bottom margin of the form, it should look similar to the one shown in Figure 11–33. Notice that none of the labels attached to the text boxes shows an ending colon. The Solstice style doesn’t include them.
Figure 11–33: You can now see the modified Products form in Design view with the changes you applied.
Finally, switch to Form view and your form should look something like the one shown in Figure 11–34. The form now looks a bit more customized-and somewhat more like the frmProducts form in the Conrad Systems Contacts application. You can find this form saved as fxmplProducts1 in the sample database.
Figure 11–34: When you switch to Form view, you can see how the modified Products form looks at this point.