A subreport is a report that's inserted in another report. When you combine reports, one of them must serve as the main report. A main report is either bound or unbound; that is, it is or isn't based on a table, query , or SQL statement .
Subforms in a report
A main report can include subforms as well as subreports, and it can include as many subforms and subreports as you want. Additionally, a main report can contain up to seven levels of subforms and subreports. For example, a report can contain a subreport, and that subreport can contain a subform or a subreport, and so on, up to seven levels deep.
Synchronizing a report and subreport
When you insert a subreport that contains information related to data in the main report, the subreport control must be linked to the main report. The link ensures that the records printed in the subreport correspond correctly to the records printed in the main report.
When you create a subreport by using a wizard or by dragging a report or datasheet from the Database window to another report, Microsoft Access automatically synchronizes the main report and subreport if:
- You have defined relationships for the tables you select, or you have defined relationships for the tables underlying the queries you select.
- The main report is based on a table with a primary key and the subreport is based on a table that contains a field with the same name as that primary key and with the same or a compatible data type . For example, if the primary key of the table underlying the main form is an AutoNumber field and its FieldSize property is set to Long Integer, the corresponding field in the table underlying the subform should be a Number field with its FieldSize property set to Long Integer. If you select a query or queries, the underlying tables in the query or queries must meet the same conditions.
Note The Sales by Category and Sales by Year reports in the Northwind sample database use subreports. To view these reports, open the Northwind database in the Samples subfolder of your Microsoft Office folder, and then open the report in Design view .