ACC2000: How to Specify a Custom Starting-Page Number for a Report

ID: Q210514


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

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

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


MORE INFORMATION

Method 1

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.


  2. Create a new report based on Employees table.


  3. Add any fields that you want by dragging them from the fields list.


  4. If they aren't yet shown on the report, click Page Header/Footer on the View menu to add a page header and footer.


  5. On the Insert menu, click Page Numbers, and then click OK.


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


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


  8. Change the ControlSource property to read as follows:


  9. 
       ="Page " & [Page] + [Enter a Starting Page Number] - 1 
Print or preview the report. Note that you are prompted for a starting page number. Starting with this number, each page is numbered consecutively on the report.

Method 2

  1. Open the sample database Northwind.mdb.


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


  3. 
    '******************************************************
    '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
     
  4. Compile the module, and then save it as basPages.


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


  6. 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:


  7. OnOpen: =GetPageChoice()
  8. Select the PageNumber text box in the footer by clicking it. Change the ControlSource property to read as follows:


  9. ="Page " & ReturnPageChoice(Page).
Print or preview the report. Note that you are prompted for a starting page number. Each page will be numbered consecutively starting with this number.


REFERENCES

For more information about the Page property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "page, pages properties" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about looping structures, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "loops" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words:

Keywords : kbusage kbdta FmrHowto
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


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