ACC2000: How to Repeat Subreport Header at Top of Page

ID: Q231808


The information in this article applies to:
  • Microsoft Access 2000

Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).


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.


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 either the Northwind.mdb or the NorthwindCS.adp sample database file.


  2. Create the following macro and then save it as RepeatSubHeader:


  3. 
       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 
  4. Create a new report called Products Sub Report based on the Products table.


  5. Place the following three text box controls in the new report's detail section:


  6. 
        Text Box:
                 Name: ProductID
        ControlSource: ProductID
    
        Text Box:
                 Name: CategoryID
        ControlSource: CategoryID
    
        Text Box:
                 Name: ProductName
        ControlSource: ProductName 
  7. On the View menu, click Report Header/Footer.


  8. Place the following three labels in the report's report header section:


  9. 
        Label:
           Name: Text1
        Caption: ProductID
    
        Label:
           Name: Text2
        Caption: CategoryID
    
        Label:
           Name: Text3
        Caption: ProductName 
  10. Set the OnPrint property of the report header section to the following macro:


  11. 
        RepeatSubHeader.SubRH 
  12. Set the OnFormat property of the report footer section to the following macro:


  13. 
        RepeatSubHeader.SubRF 
  14. Create a new report called Categories Main Report based on the Categories table.


  15. 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.


  16. Place the following text box in the Categories Main Report report's page header section:


  17. 
        Text Box:
           Name: Flag
        Visible: No 
  18. Place the following three text boxes in the Categories Main Report report's detail section:


  19. 
        Text Box:
                 Name: CategoryID
        ControlSource: CategoryID
    
        Text Box:
                 Name: CategoryName
        ControlSource: CategoryName
    
        Text Box:
                 Name: Description
        ControlSource: Description 
  20. Embed the Products Sub Report report into 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.


  21. 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 property to 0.


  22. Set the OnFormat property of the report header section of the Categories Main Report report to the following macro:


  23. 
        RepeatSubHeader.MainRH 
  24. Set the OnPrint property of the page header section of the Categories Main Report report to the following macro:


  25. 
        RepeatSubHeader.MainPH 
  26. 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 previous example 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 of the previous example 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 


REFERENCES

For more information about events during printing, click Microsoft Visual Basic Help on the Help menu, type Print Events in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about report OnFormat and OnPrint properties, click Microsoft Visual Basic Help on the Help menu, type OnFormat and/or OnPrint in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Additional query words:

Keywords : kbusage kbdta RptSub
Version : WINDOWS:2000
Platform : WINDOWS
Issue type :


Last Reviewed: November 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.