What Is A Subform?
A subform is a form that is placed in a parent form, called the
main form. Subforms are particularly useful to display data from
tables and queries that have one-to-many relationships. For example,
in the sample below, data on the main form is drawn from an item
information table while the subform contains all of the orders for
that item. The item record is the "one" part of this one-to-many
relationship while the orders are the "many" side of the
relationship since many orders can be placed for the one item.
The remainder of this page explains three methods for creating
subforms and they assume that the data tables and/or queries have
already been created.
Create a Form and Subform at Once
Use this method if neither form has already been created. A main
form and subform can be created automatically using the form wizard
if table relationships are set properly
or if a query involving multiple tables is selected. For example,
a relationship can be set between a table containing customer information
and one listing customer orders so the orders for each customer
are displayed together using a main form and subform. Follow these
steps to create a subform within a form:
- Double-click Create form by using wizard on the database
- From the Tables/Queries drop-down menu, select the first
table or query from which the main form will display its data.
Select the fields that should appear on the form by highlighting
the field names in the Available Fields list on the left
and clicking the single arrow > button or click the
double arrows >> to choose all of the fields.
- From the same window, select another table or query from the
Tables/Queries drop-down menu and choose the fields that
should appear on the form. Click Next to continue after
all fields have been selected.
- Choose an arrangement for the forms by selecting form with
subform(s) if the forms should appear on the same page or
Linked forms if there are many controls on the main form
and a subform will not fit. Click Next to proceed to the
next page of options.
- Select a tabular or datasheet layout for the form and click
- Select a style for the form and click Next.
- Enter the names for the main form and subform. Click Finish
to create the forms.
- New records can be added to both tables or queries at once by
using the new combination form.
If the main form or both forms already exist, the Subform Wizard
can be used to combine the forms. Follow these steps to use the
- Open the main form in Design View and make sure the Control
on the toolbox is pressed in.
- Click the Subform/Subreport icon
on the toolbox and draw the outline of the subform on the main
form. The Subform Wizard dialog box will appear when the mouse
button is released.
- If the subform has not been created yet, select "Use existing
Tables and Queries". Otherwise, select the existing form
that will become the subform. Click Next to continue.
- The next dialog window will display table relationships assumed
by Access. Select one of these relationships or define your own
and click Next.
- On the final dialog box, enter the name of the subform and click
Use this method to create subforms from two forms that already
exist. Make sure that the table relationships have already been
set before proceeding with these steps.
- Open the main form in Design View and select Window|Tile
Vertically to display both the database window and the form
- Drag the form icon beside the name of the subform onto the detail
section of the main form design.