Help and Support
 

powered byLive Search

ACC: How to Repeat Subreport Header at Top of Page

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:120907
Last Review:January 19, 2007
Revision:2.1
This article was previously published under Q120907
Moderate: Requires basic macro, coding, and interoperability skills.
On This Page

SUMMARY

This article describes how to repeat a subreport's header when the subreport spans multiple pages.

NOTE: This method works best for one subreport. Attempting to repeat the subreport header for multiple subreports requires a set of controls in the page header and a flag for each subreport. Then the code must check 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 sample files, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0) and RptSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

145777 (http://support.microsoft.com/kb/145777/EN-US/) ACC95: Microsoft Access Sample Reports Available in Download Center

175072 (http://support.microsoft.com/kb/175072/EN-US/) ACC97: Microsoft Access 97 Sample Reports Available in Download Center

Back to the top

MORE INFORMATION

The method demonstrated in the following example uses a flag in the page header to indicate whether the subreport spans multiple pages. When the subreport's report header is printed the flag is set to 1. When the subreport's report footer is printed, the flag is set to 0. When the page header is printed, if the flag is set to 1, then the subreport spans multiple pages and the subreport's header should be repeated.

The following example demonstrates how to cause a subreport's header to be repeated if the subreport spans multiple pages:
1.Open the sample database Northwind.mdb (or NWIND.MDB in versions 1.x and 2.0).
2.Create the following macro, and then save it as RepeatSubHeader:
       Macro Name   Condition   Action
       ------------------------------------
       MainRH                   SetValue
       MainPH       [Flag]=0    CancelEvent
       SubRH                    SetValue
       SubRF                    SetValue

       MainRH Actions
       ------------------------------------------------
       SetValue
          Item: Reports![Categories Main Report]![Flag]
          Expression: 0

       SubRH Actions
       ------------------------------------------------
       SetValue
          Item: Reports![Categories Main Report]![Flag]
          Expression: 1

       SubRF Actions
       ------------------------------------------------
       SetValue
          Item: Reports![Categories Main Report]![Flag]
          Expression: 0
						
3.Create a new report called Products Sub Report based on the Products table.
4.Place the following three text box controls in the new report's detail section:
       Text Box:
          ControlName: ProductID
          ControlSource: ProductID
       Text Box:
          ControlName: CategoryID
          ControlSource: CategoryID
       Text Box:
          ControlName: ProductName
          ControlSource: ProductName
						

NOTE: In versions 1.x and 2.0, type a space in Product ID, Category ID, and Product Name.
5.On the View menu, click Report Header/Footer.
6.Place the following three labels in the report's report header section:
       Label:
          ControlName: Text1
          Caption: ProductID
       Label:
          ControlName: Text2
          Caption: CategoryID
       Label:
          ControlName: Text3
          Caption: ProductName
						
7.Set the report header section's OnPrint property to the following macro:
       RepeatSubHeader.SubRH
						
8.Set the report footer section's OnFormat property to the following macro:
       RepeatSubHeader.SubRF
						
9.Create a new report called Categories Main Report based on the Categories table.
10.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.
11.Place the following text box in the Categories Main Report report's page header section:
       Text Box:
          ControlName: Flag
          Visible: No
						
12.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
						
13.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.
14.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.
15.Set the OnFormat property of the report header section of the Categories Main Report report to the following macro:
       RepeatSubHeader.MainRH
						
16.Set the OnPrint property of the page header section of the Categories Main Report report to the following macro:
       RepeatSubHeader.MainPH
						
17.Preview or print the report. Note that the subreport's header information is repeated when the subreport spans multiple pages.

Back to the top

Displaying Main Report Information on Every Page

The example above assumes that you do not want anything except the subreport header to be printed in the main report's page header. If you do want to print other information, you will need to hide and unhide each subreport header control in the page header. Change the MainPH macro in step 2 above to:
   Macro Name   Condition   Action
   -------------------------------------------------
   MainPH       [Flag]=0    SetValue
                               Item: [Text1].visible
                               Expression: False
                ...         SetValue
                               Item: [Text2].visible
                               Expression: False
                ...         SetValue
                               Item: [Text3].visible
                               Expression: False
                [Flag]=1    SetValue
                               Item: [Text1].visible
                               Expression: True
                ...         SetValue
                               Item: [Text2].visible
                               Expression: True
                ...         SetValue
                               Item: [Text3].visible
                               Expression: True
				

Back to the top

REFERENCES

For more information about events during printing, type "Print Events" in the Office Assistant, click Search, and then click to view "Print Event."

For more information about report OnFormat and OnPrint properties, search on "OnFormat," and "OnPrint," using the Microsoft Access 97 Help Index.

Back to the top


APPLIES TO
Microsoft Access 1.0 Standard Edition
Microsoft Access 1.1 Standard Edition
Microsoft Access 2.0 Standard Edition
Microsoft Access 95 Standard Edition
Microsoft Access 97 Standard Edition

Back to the top

Keywords: 
kbhowto kbusage KB120907

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.