UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Page Numbering by Group    
Page Numbering by Group

Image:NotifCleanup.gif This page requires general cleanup in formatting or text to better fit the UA Wiki Guidelines

This is a set of instructions to show how you can set up a page numbering system that resets every time your report starts a new group. For example, if you have a report that prints several multi-page invoices at once, you would want your page numbering to reset to 1 for each new invoice in the report.

1. Open your report in Design View.

2. Create or click on the unbound textbox that you're using to display the page number in the page footer.

3. Open the Properties box, if necessary.

4. In the "Other" tab of the Properties box, set the Name property to "txtPageNumber".

Your report should include a Group Header or Footer that prints each time a new group is printed.

5. Click on the grey bar that defines the top of this group's header/footer.

6. Select the Event tab in the Properties box

7. Click once on the OnFormat event for the group header/footer, and a small button with three dots appears.

8. Click that small box, and select "Code Builder" from the pop-up dialog box that appears.

At this point you are taken to the Visual Basic Editor, and a subroutine header & footer are created for that event.

9. Between the header and footer, place the following code:

intPageNumber = 0

This resets the variable that stores your page number. The variable will need to be defined before we can work with it, however.

10. Next, place the following code near the top of the code module, below "Option Compare Database", but above any subroutines that are already in this code module:

Dim intPageNumber As Integer

This sets up the global variable "intPageNumber", which will store the current page number. The reason this variable is global (instead of being defined inside the OnFormat event of the header/footer), is because Access needs to refer to it from more than one subroutine.

11. Back in your Report's Design View, click on the grey bar that defines the top of the Page Footer where your page number textbox is residing.

12. In the Properties box, click once on the OnFormat event for the page footer, and then click on the little box with three dots to create code for this event.

13. In the OnFormat event for the Page Footer, place the following code:


Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)

   intPageNumber = intPageNumber + 1
   Me.txtPageNumber = intPageNumber

End Sub

This increments the page number by 1 each time the page footer is formatted, and assigns the current page number value to the textbox.

That is essentially all you need to do. When the Group Header/Footer is printed, the page number is reset. When the Page Footer is printed, the page number is incremented, then assigned to an unbound textbox in the page footer.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 13,994 times.  This page was last modified 11:22, 14 February 2012 by Jack Leach. Contributions by Glenn Lloyd and doctor9  Disclaimers