Access lets you display data that is related to records in a form or report by using a subform or subreport. The creation and management is much the same for both.
A subform or subreport is embedded in a form or report, the main form/report.
You cannot put a subreport onto a form in Access 2007 but you can in later versions of Access.
The form or report that contains a subform or subreport is called the parent. The subform or subreport is called the child.
Form with subform on tab control; Report with subreport in Detail
Combined
report: Subreports can also go into the Report Header or Footer as well as the Page Header or Footer, not just
the Detail section. This
lets you combine several reports into a single one. The Detail
section could even be hidden!
The illustration shows one subreport in the Report Header, which will appear only once, and another the Detail section, which will be different for each record.
Nesting: You can nest up to 7 levels of subforms inside forms or subreports inside reports. "Nesting" means you have a main form that contains a subform, which itself contains a subform, which also contains a subform... for 7 levels deep. It's the same for reports. Having that many levels would certainly be unusual!
Total number: There is no particular limit to how many separate subforms or subreports you can put into a form or report.
The wizard for inserting a subform/subreport has just three or four steps. The illustrations below are for a subform but the wizard is the same for a subreport. Only the title bar is different.
Step
1: Pick source for the subform/subreport. You can use an existing form
or report or you can pick an existing table or query.
You cannot create anything new from inside the wizard. The object must already exist.
Step
2: Select fields - for table or query.
This step is skipped if you choose to use an existing form or report.
Step
3: Create a link between the main and the sub.
The wizard makes a guess and cleverly offers you in words what you want to
see rather than making you pick fields to match up.
Step
4: Name the new object.
If you used a table or query, Access automatically adds your new subform to
the Navigation pane, in either Forms or Reports.
The name you entered will appear in the label for the control. Choose a name that makes it clear that this object is part of another object.
From
earlier lessons on tables, you learned that a table or query that
has a One-to-Many relationship with another one can show a subdatasheet of related records. The
illustration shows a table of Students with a subdatasheet for the scores
of the student. The Student table is
the One side and the Scores table is the Many side of the relationship.
One student has many scores.
The usual type of subform/subreport shows this kind of related data, synchronized to the current record on the main form or report. Very useful!
A subform can use any view to display the data. Datasheet View or Form View are, of course,
the most common. You can even edit the data in the subform or add new
records. Sweet!
Subform as datasheet; Subform as continuous form
In
the Property Sheet for the subform/subreport, there are two properties
that define the connection between the Parent (form/report) and the Child
(subform/subreport). Both are required to create the link.
Link Child Fields is for the field or fields on the subform/subreport that match the field or fields from the main form/report in Link Master Fields. Both properties must be set for the subform/subreport to synchronize with the main form/report.
The field names are usually the same but can be different. The data types, however, must be the same or compatible. These are usually the fields that join the underlying tables. Otherwise you cannot be sure that there is a unique choice.
You can edit the Link properties yourself if Access loses track of the matching fields. Be careful to pick the right fields! If you are wrong, you will pull the wrong data and it may not change correctly when you change records on the main form/report.
The subform/subreport will be blank if Access cannot connect the data.
Conditions must be met for Access to automatically link the child and parent: