• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Working with Forms > Creating Subforms

Creating Subforms

Records in one table are often related to more than one record in another table. For instance, one author in your Authors table can have more than one book listed in your Books table. Standard forms don't illustrate these one-to-many relationships well, but forms with subforms do.

For instance, it's easy to display a list of authors in a form. What you can't do in a simple form is show the books that each author has written. If you add a subform based on a table listing book titles, Access can find the books a specific author has written and display them in the subform.

You should pick the object in your database that contains the fields you want to display in your subform; Access lets you choose the fields you want to show in the subform. Using a query (covered in Chapter 5) includes the fields you've included in your query results, though they can come from more than one table (or another query).

If you use an existing form (as we do in the following example), Access will ask you to give the subform a unique name. This is true for subforms based on tables and queries as well.

To create a subform:

1.
Open the form to which you want to add a subform, open the Toolbox if necessary, and click the Subform/Subreport button ( Figure 4.40 ).

Figure 4.40. Open the Toolbox to display the Subform Control Wizard.


2.
Click the place on the form where you want your subform to appear.

The best place to put a subform is usually toward the bottom of the form, below the information relating to the record displayed in the main form.

The Subform Wizard launches once you've clicked the target.

3.
Select the source for your subform by clicking either the "Use existing Tables and Queries" option button or the "Use an existing form" button. Click Next to continue ( Figure 4.41 ).

Figure 4.41. Select the source for your subform.


The next wizard screen appears, containing a list of the fields in the form and a list of the fields in the subform.

4.
Click the name of the field that you want to link your form and subform. Click Next ( Figure 4.42 ).

Figure 4.42. You don't need to use all of the fields from a subform's source; you can add only the ones that you want.


You can remove fields from the Selected Fields pane by clicking either the < button (to remove one field) or the << button (to remove them all).

5.
Type a name for your subform and click Finish.

You should probably leave the word "subform" in your new subform's name so it will be easier to recognize in your object lists.

Tip

If you want to use all of the fields in a table, you should check if a form has been created from that table. If one exists, look it over and use it if it fits!


  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint