Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q210514
Moderate: Requires basic macro, coding, and interoperability skills.

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

For a Microsoft Access 2002 version of this article, see 299025 (http://support.microsoft.com/kb/299025/EN-US/ ) .

↑ Back to the top


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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

↑ Back to the top


More information

Method 1

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow 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:
       ="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:
    '******************************************************
    '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.
  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 PageNumber text box in the footer by clicking it. Change the ControlSource property to read as follows:
    ="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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB210514, kbusage, kbdta, kbhowto

↑ Back to the top

Article Info
Article ID : 210514
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 315