Microsoft KB Archive/299025

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

Article ID: 299025

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q299025



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 2000 version of this article, see 210514.



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.



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.

 Open the sample database Northwind.mdb. Create a new report based on Employees table. Add any fields that you want by dragging them from the fields list. If they aren't yet shown on the report, click Page Header/Footer on the View menu to add a page header and footer. On the Insert menu, click Page Numbers, and then click OK. Create a new unbound text box in the header or footer section.</li> Click to select the new field, and then on the View menu, click Properties.</li>  Change the ControlSource property to read as follows: <pre class="fixed_text">  =&quot;Page &quot; & [Page] + [Enter a Starting Page Number] - 1 </li></ol>

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
<ol> Open the sample database Northwind.mdb.</li>  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(&quot;Enter a Starting Page Number:&quot;,&quot; _                    Number Report&quot;, &quot;1&quot;) If Not (IsNumeric(choice)) Then MsgBox &quot;Value Entered is not a Number.&quot; 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

</li> Compile the module, and then save it as basPages .</li> Open the Summary Of Sales By Quarter report in Design view.</li> 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

</li> Select the PageNumber text box in the footer by clicking it. Change the ControlSource property to read as follows:

=&quot;Page &quot; & ReturnPageChoice(Page).

</li></ol>

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.

<div class="references_section">