ACC: How to Print a Conditional Page Header in a Report 1.x/2.0

Last reviewed: June 3, 1997
Article ID: Q105516
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

Novice: Requires knowledge of the user interface on single-user computers.

This article describes how to print a conditional page header using an example that forces the page header (which contains the column header labels), to print on consecutive pages of the report if a data group spans more than one page.

The technique described in this article works for Microsoft Access versions 1.x and 2.0. However, an alternative method for version 2.0 is described in the Solutions sample application. See the "References" section of this article for a complete reference to this method.

MORE INFORMATION

Reports print group header information once per group, even if the group of data spans more than one page. In reports, a common layout is to place the grouping value in the group header along with the column labels. However, because this data is not repeated when a group spans more than one page, the column header labels are not repeated on the subsequent page(s).

To create conditional headers, you must create a new page before each group of data and set a flag from the group header to determine when the page header should print. Then, from the group footer, set the flag back so that the page header does not print at the beginning of the next group.

To create the conditional headers, follow these steps:

  1. Open the sample database NWIND.MDB.

  2. Create a new form called FlagForm. This form is used to store a global variable.

  3. Create one unbound control and set the following property:

          Name: Flag
    

    NOTE: In Microsoft Access version 1.x, the Name property is called the ControlName property.

  4. Create the following new macro, and name it Test:

          Macro Name        Condition                       Action
          -------------------------------------------------------------
          SetFlag                                           SetValue
          ShrinkPageH        Forms![FlagForm]![Flag]=1      CancelEvent
          FlagOn                                            SetValue
          FlagOff                                           SetValue
    
          Test actions
          ---------------------------------
          SetFlag
             Item:  Forms![FlagForm]![Flag]
             Expression: 1
          CancelEvent: no arguments
          FlagOn
             Item:  Forms![FlagForm]![Flag]
             Expression: 0
          FlagOff
             Item:  Forms![FlagForm]![Flag]
             Expression: 1
    
    

  5. Create a new blank report called PrintHeaders based on the Products table:

        a. Set the following report header properties:
    

             OnFormat: Test.SetFlag
             Height: 0
    
        b. Set the following page header property:
    
             OnFormat: Test.ShrinkPageH
    
        c. Create a label in the page header section and set the following
           property:
    
             Caption: Continued from Previous Page...
    
        d. Create a grouping for the Category ID and set following properties:
    
             Group Header: Yes
             Group Footer: Yes
    
        e. Set the following group header properties:
    
             OnFormat: Test.FlagOn
             ForceNewPage: Before Section
    
        f. Create a control in the group header section bound to the Category
           ID field.
    
        g. Create a text box control bound to the Product Name field in the
           detail section.
    
        h. Set the height property for the detail section to 2 inches.
           (This is to create groups of data that span more than one page.)
    
        i. Set the following group footer property:
    
             OnFormat: Test.FlagOff
    
    

  6. View the FlagForm form in Datasheet view.

  7. Preview the PrintHeaders report.

  8. Scroll through the report. Note the page headers for the groups.

REFERENCES

You can find information, instructions, and examples in the Solutions sample application (SOLUTION.MDB) included with Microsoft Access version 2.0. For more information about printing a conditional page header, open the SOLUTION.MDB database usually located in the ACCESS\SAMPAPPS directory. Select "Control what you print on reports" in the Select A Category Of Examples box, then "Repeat a group name at the top of a column or page" in the Select An Example box.

For more information about repeating group names, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q93927
   TITLE     : ACC: Repeating Group Name at Top of New Column or Page
               (2.0)
 

	
	


Keywords : kbusage McrHowto RptEvent RptLayou
Version : 1.0 1.1 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.