ACC1x: How to Print Total Number of Pages on Each Page of Report

ID: Q97517


The information in this article applies to:


SUMMARY

You can print the page number on each page of a report by using the Page property in a text box control in the page footer. The example below also shows you how to print the total number of pages in the report on each page (for example, 1/<n>, where <n> is the total number of pages).

The sample program below uses the SendKeys statement to go to the end of the report, stores the total number of pages in a global variable, then returns to the beginning of the report to print or preview the report.

NOTE: This method may not work with all reports. Below are four known problems with this method:

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual.


MORE INFORMATION

To print the total number of pages in a report at the bottom of each page, do the following:

  1. Open a new module or a previously created module and enter the following sample code:

    NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore when re-creating this code in Access Basic.
    
          '*************************************************************
          'Declarations section of the module
          '*************************************************************
          Option Explicit
          Global TotalPages as Integer
    
          '*************************************************************
          'Create the following functions in the module.
          '*************************************************************
          Function GetTotalPages()
             GetTotalPages = TotalPages
          End Function
    
          Function GotoEnd()
             TotalPages = 0
             SendKeys "%z{END}", False
             ' SendKeys does not work if report is maximized
          End Function
    
          Function SaveTotalPages(TotPgNum As Integer)
             If TotalPages = 0 Then
                TotalPages = TotPgNum
                SendKeys "{HOME}", False
             End If
          End Function 


  2. Open your report in Design view.


  3. From the View menu, choose Properties to display the property sheet. Add the following function to the report's OnOpen property:

    OnOpen: =GotoEnd()


  4. Place a text box control called MyPage in the page footer:
    
          Object: Text Box
          ----------------
          ControlName: MyPage
             ControlSource: =Page
             Visible: No 


  5. Change the report footer's OnFormat property to:

    OnFormat: =SaveTotalPages([MyPage])


  6. Place a text box control in the page footer as follows:
    
          Object: Text Box
          ----------------
          ControlName: PageNum
             ControlSource: =Page & "/" & GetTotalPages() 


When you print the report, the text box control prints the page number as 1/<n>, where <n> is the total number of pages in the report.


Keywords          : kbusage RptLayou 
Version           : 1.0 1.1
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: March 20, 1999