Creating Simple Forms

As with many other things in Access, there is more than one way to create a form. You can choose from the following three ways:

  • You can use an AutoForm wizard, which automatically creates a form displaying all the data in a table or query.

  • You can use the Form wizard, which automatically creates a form after you specify which fields you want the form to display (and a few formatting choices).

  • You can create a form from scratch in design view.

The Wizard Way

Without a doubt, the quickest and easiest way to create a form is to let Access do the work for youuse a wizard whenever you can. The two types of form wizards are as follows :

  • AutoForm Wizard Creates a specific type of form and displays all the data in a table or query, without asking you any questions.

  • Form Wizard Lets you choose the type of form it produces and which data the form displays.

Note

graphics/note.gif

You can download the Chapter 8.mdb sample file for this chapter from http://www.quepublishing.com/. If you want to follow along with our examples, download Chapter 7.mdb .


The AutoForms

Five AutoForm wizards are available, and each one automatically creates a specific type of form:

  • Columnar Stacks the fields, one on top of the other, beginning with the first field in the table or query until all the fields are lined up in a single column.

  • Tabular Aligns the fields beside each other in a row, positioning the first field in the table or query at the far left and adding subsequent fields in the same order they appear in the table or query.

  • Datasheet Displays all the fields in the table or query in the familiar table (or datasheet) row and column format. The form will look just like a table.

  • PivotTable The wizard opens the form in PivotTable view. (We won't review this wizard in this chapter.)

  • PivotChart The wizard opens the form in PivotChart view. (We won't review this wizard in this chapter.)

Note

graphics/note.gif

The PivotTable and PivotChart forms are for advanced analysis of large amounts of data. You won't need to use them in this book.


To quickly create a data entry form based on the Plants table, follow these steps:

  1. Click the Tables shortcut in the Object bar, and then select the Plants table in the Database window.

  2. Select Form from the Insert menu. Or, click the drop-down arrow next to the New Object button on the main Access toolbar and select Form from the list that appears.

  3. In the resulting New Form dialog box, select the AutoForm: Columnar item, as shown in Figure 8.1, and click OK . Or, you can simply double-click the wizard. If you didn't choose the table beforehand, you can do so now by selecting a table or query from the drop-down control at the bottom of the dialog box.

    Figure 8.1. Select the AutoForm: Columnar Wizard from the New Form dialog box.

    graphics/08fig01.gif

  4. Save the resulting form, shown in Figure 8.2, by clicking the Save button on the Form view toolbar. Then, enter the name Plants in the Save As dialog box and click OK .

    Figure 8.2. A columnar form stacks the controls vertically.

    graphics/08fig02.gif

Figures 8.3 and 8.4 show two more forms. Specifically, we used the AutoForm: Tabular Wizard to base a form on the Catalogs table and the AutoForm: Datasheet Wizard to base a form on the Types table. Creating these forms will help you practice with the AutoForm feature and show you the variety of forms you can get with a minimal amount of effort. Sometimes, though, you'll find that AutoForms just aren't good enough for what you want to do with the database. We'll show you how to create more complex and customized forms in the rest of the chapter.

Figure 8.3. The tabular form aligns the controls in the same row.

graphics/08fig03.jpg

Figure 8.4. Datasheet forms look just like a table (or datasheet).

graphics/08fig04.gif

Note

graphics/note.gif

In Chapter 6, "Tapping the Power of Relationships," you added a lookup field to the TypeID field in the Plants table. We told you then that a form will inherit a lookup field, and that's just what happened with the Plants form. The TypeID control in the form shown in Figure 8.2 is a combo box controlyou can tell by the dropdown arrow to the right of the control. You'll learn more about combo box controls in Chapter 13, "Customizing Forms."


About Subforms

You might have noticed that the New Object button's list includes an AutoForm item, but you didn't select it in the previous example. This wizard automatically produces a columnar form similar to the AutoForm: Columnar Wizard used earlier. But there's an important difference between these two wizards: The wizard in the New Object list includes a table's relationships in the finished form. As you'll see, the relationship between tables translates into a relationship between forms. Specifically, the form has a subform (an embedded form within the main form) that displays the related data.

We'll show the difference between these two forms in the following steps. Let's use the AutoForm Wizard on the New Object list to base a form on the Catalogs table. To do so, follow these steps:

  1. Click the Tables shortcut in the Object bar, and then Select Catalogs in the Database window.

  2. Open the New Object button's drop-down list and select AutoForm . Figure 8.5 shows the new form. Note that the wizard uses the name of the main table (Catalogs) as the title of the form, even though the form shows data from both the Catalogs table and the Plants table. Save this form as CatalogsAndPlants .

    Figure 8.5. The AutoForm Wizard accommodates the Catalogs table's relationship to the Plants table.

    graphics/08fig05.jpg

This form is special because it includes data from both the Catalogs and the Plants tables, even though you didn't tell the wizard to do so. That's because the wizard encountered the relationship between the two tables and included a subform to display the related plant information for the current catalog.

The main form displays the catalog records, and the subform displays plants where the primary/foreign key value in the two tables matches. In other words, the subform displays any plants where the CatalogName field matches the value in the main form's Name field. This might or might not be what you want. Just remember, you can always dump the form and use one of the other AutoForm wizards. Or, you can use the Form Wizard to exercise a bit more control over the results. Close the form before continuing. You'll learn more about building and customizing subforms in Chapter 13.

Note

graphics/note.gif

If you used the New Object list's version of the AutoForm to create a form based on the Plants table, it will not create a subform, even though that table has two relationships: one with Catalogs and one with Types. The wizard creates a subform when the form you specify contains the primary key value in a relationship. The primary key in Plants is not related to any other tableonly the Plants table's foreign key values are related to the other tables.


The Form Wizard

The Form Wizard creates the form for you but allows you to set limits to the data the form will display. You start the wizard the same way you do an AutoForm wizard, except in the New Form dialog box, you select Form Wizard.

Now, let's look at the options the Form Wizard enables you to select as you create a new form. Specifically, we'll base a form on both the Types and Plants tables. To do so, follow these steps:

  1. Display the New Form dialog box by selecting Form from the New Object button's drop-down list or selecting Form from the Insert menu.

  2. Select Form Wizard in the New Form dialog box.

  3. Select Types from the drop-down control, and click OK .

  4. The Available Fields list displays all the fields in the Types table. You'll move the fields you want to add to the form to the Selected Fields list by clicking one of the arrow buttons the same way that you did with the Simple Query Wizard in Chapter 7, "Retrieving Data with Queries." The single arrow button (>) moves one field at a time; the double arrow button (>>) moves all the fields to the Selected Fields list. For this example, click the double arrow button to move all the fields to the Selected Fields list, as shown in Figure 8.6.

    Figure 8.6. Include both fields from the Types table.

    graphics/08fig06.gif

  5. Now, let's add some data from the Plants table. To do so, simply select Plants from the Tables/Queries drop-down list, which updates the Available Fields list accordingly . Move the CommonName, LatinName, and CatalogName fields to the Selected Fields list, as shown in Figure 8.7. Click Next to continue.

    Figure 8.7. Include four fields from the Plants table.

    graphics/08fig07.gif

  6. Because you selected fields from more than one table, the wizard offers three ways to display the related data. The wizard defaults to displaying the plant records data in a subform and shows you a schematic picture of this option.

  7. To see the other options, select the By Plants item in the list to the left, and the wizard updates the sample form to the right accordingly. Notice that the wizard also selects the Single Form option at the bottom of the dialog box. Reselect the By Types item and click the Linked Forms option to view that sample, which creates two linked forms. Be sure to reselect the Form with SubForm(s) option before clicking Next to continue.

  8. The next window enables you to choose the type of form you want: Tabular, Datasheet, PivotTable, or PivotChart. Select Tabular , as shown in Figure 8.8, and click Next .

    Figure 8.8. Select the Tabular option.

    graphics/08fig08.jpg

  9. At this point, you can choose from any number of autoformats . An autoformat lets you set the default colors and fonts for a form, among other things. The wizard defaults to Standard, and that's the format we'll keep. Click Next without changing this option.

  10. In the last window, rename the form and the subform CatalogsMain and PlantsSub , respectively, as shown in Figure 8.9. You can also select to open the form in form view so you can start entering data or in design view, where you can modify the form's design. (It's common to tweak the product of a wizard.) Open the form in form view by clicking Finish without changing the wizard's selection.

    Figure 8.9. Name the two forms (the main form and subform) and click Finish.

    graphics/08fig09.jpg

The new form, shown in Figure 8.10 lists the type possibilities in the main form. The subform displays the plant records for the type that's current in the main form.

Figure 8.10. The wizard has produced a form that displays the plant names in a subform.

graphics/08fig10.gif

You'll see that forms contain the same navigation buttons that you're already familiar with from datasheets . If you click the Next Record navigation button on the subform (refer to Figure 8.10), the selection arrow in the left margin of the subform advances one row, from Black-Eyed Susan to Cosmos. If you click the Next Record navigation button on the main form to display a new type, the subform updates the plant records accordingly. As you can see in Figure 8.11, type 2 (edible plants) currently has no related plant records. Close the form.

Figure 8.11. As yet, no edible plants exist in the database.

graphics/08fig11.gif

Creating a Form in Design View

You don't need a wizard to create a form. Although the wizards do a good job, sometimes simply starting from scratch can be more efficient. When this is the case, open a blank form in design view and start adding controls. To open a blank form in design view, do the following:

  1. Select Form from the Insert menu. Or, select Form from the New Object button's drop-down list.

  2. Design View is the default option in the resulting New Form dialog box, and this is the option you want.

  3. If you didn't specify a table or query in step 1, select the appropriate table or query now in the drop-down control.

  4. Click OK to open a blank form in design view, as shown in Figure 8.12.

    Figure 8.12. A blank form in design view.

    graphics/08fig12.jpg

In Chapter 13, you'll learn how to customize a form in design view by adding and formatting controls and formatting the form itself. For now, just close the form without saving it.



Absolute Beginner's Guide to MicrosoftR Access 2002
Absolute Beginner's Guide to MicrosoftR Access 2002
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 133

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