ACC: How to Specify a Custom Starting Page Number for a Report

Last reviewed: August 29, 1997
Article ID: Q100156
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

In Microsoft Access reports, page numbering always starts with the number 1. However, you may want your report to have page numbering that starts with some number other than 1. This article describes two methods of defining custom starting page numbers. Both methods provide custom page numbers; however, the second method uses Visual Basic for applications and can therefore include error checking. This method is more complex, but avoids the possibility that a nonnumeric value will be entered when you are prompted for a starting number.

MORE INFORMATION

Method 1

  1. Open the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 1.x and 2.0)

  2. Create a new report based on Employees table.

  3. Add fields by dragging them from the fields list

  4. On the View menu, click Page Header/Footer.

  5. In Microsoft Access 7.0 and 97:

         On the Insert menu, click Page Number, and then click OK.
    

    In Microsoft Access 1.x and 2.0:

         Create a new unbound text box in the header or footer section.
    

  6. Click to select the new field and on the View menu, click Properties.

  7. Change the ControlSource property to read as follows:

          ="Page " & [Page] + [Enter a Starting Page Number] - 1
    

When you preview or print the report, you will be prompted for a starting page number. Each page will be numbered consecutively starting with this number.

Method 2

This part of the article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

  1. Open Northwind.mdb (NWIND.MDB in Microsoft Access 1.x and 2.0).

  2. Create a new module and type the following code:

          '******************************************************
          'Declarations Section of Module
          '******************************************************
          Option Explicit
          Global PageChoice As Integer
    

          '===========================================================
          'Create the following GetPageChoice() function in the Module
          '===========================================================
          'This function is called in the OnOpen property of the Report.
          Function GetPageChoice ()
    
             Dim choice As String
             Do
                choice = InputBox("Enter a Starting Page Number:"," _
                              Number Report", "1")
                If Not (IsNumeric(choice)) Then
                   MsgBox "Value Entered is not a Number."
                End If
             Loop While Not (IsNumeric(choice))
             PageChoice = CInt(choice)
          End Function
    
          '==============================================================
          'Create the following ReturnPageChoice() function in the Module
          '==============================================================
          'This function is called by the text box that will contain the
          ' pagenumber.
          Function ReturnPageChoice (pgnumber As Integer)
             ReturnPageChoice = PageChoice + pgnumber - 1
          End Function
    
    

  3. Compile the module, and then save it as "basPages" (without the quotation marks).

  4. Open the Summary Of Sales By Quarter report in Design view.

  5. On the Edit menu, click Select Report, and then on the View menu, click Properties to display the property sheet. Change the OnOpen property to read as follows:

          OnOpen: =GetPageChoice()
    

  6. Select the text box PageNumber in the footer by clicking it. Change the ControlSource property to read as follows:

          ="Page " & ReturnPageChoice(Page).
    

When you preview or print the report, you will be prompted for a starting page number. Each page will be numbered consecutively starting with this number.

REFERENCES

For more information about the Page property, search for "Page Numbers," and then "Page, Pages Properties" using the Microsoft Access 97 Help Index.

For more information about looping structures, search for "loops" using the Microsoft Access 97 Help Index.

Keywords          : kbusage PgmHowTo
Version           : 1.0 1.1 2.0 7.0 97
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: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.