This article was previously published under Q120907
This article has been archived. It is offered "as is" and will no longer be updated.
Moderate: Requires basic macro, coding, and interoperability skills.
This article describes how to repeat a subreport's header when thesubreport spans multiple pages.
NOTE: This method works best for one subreport. Attempting to repeatthe subreport header for multiple subreports requires a set of controlsin the page header and a flag for each subreport. Then the code mustcheck each flag and hide or show the appropriate sets of controls.This code is not easy to maintain.
NOTE: This article explains a technique demonstrated in the samplefiles, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0)and RptSmp97.exe (for Microsoft Access 97). For information about howto obtain these sample files, please see the following articles in theMicrosoft Knowledge Base:
145777 ACC95: Microsoft Access Sample Reports Available in Download Center
175072 ACC97: Microsoft Access 97 Sample Reports Available in Download Center
The method demonstrated in the following example uses a flag in the pageheader to indicate whether the subreport spans multiple pages. When thesubreport's report header is printed the flag is set to 1. When thesubreport's report footer is printed, the flag is set to 0. When the pageheader is printed, if the flag is set to 1, then the subreport spansmultiple pages and the subreport's header should be repeated.
The following example demonstrates how to cause a subreport's header to berepeated if the subreport spans multiple pages:
Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.x and 2.0).
Create the following macro, and then save it as RepeatSubHeader:
Set the report header section's OnPrint property to the following macro:
Set the report footer section's OnFormat property to the following macro:
Create a new report called Categories Main Report based on the Categories table.
Copy the controls from the Product Sub Report report's report header section and paste them into the page header section of the Categories Main Report report.
Place the following text box in the Categories Main Report report's page header section:
Text Box: ControlName: Flag Visible: No
Place the following three text boxes in the Categories Main Report report's detail section:
Text Box: ControlName: CategoryID ControlSource: CategoryID Text Box: ControlName: CategoryName ControlSource: CategoryName Text Box: ControlName: Description ControlSource: Description
Embed the Products Sub Report report in the Categories Main Report report by dragging the Products Sub Report report from the Database window to the detail section of the Categories Main Report report.
On the View menu, click Report Header/Footer to add a report header and footer to the main report. If you do not want a main report header or footer, set the header or footer section's height to 0.
Set the OnFormat property of the report header section of the Categories Main Report report to the following macro:
Set the OnPrint property of the page header section of the Categories Main Report report to the following macro:
Preview or print the report. Note that the subreport's header information is repeated when the subreport spans multiple pages.
Displaying Main Report Information on Every Page
The example above assumes that you do not want anything except thesubreport header to be printed in the main report's page header. If you dowant to print other information, you will need to hide and unhide eachsubreport header control in the page header. Change the MainPH macro instep 2 above to: