Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
Dim currentPage As Integer
Dim setSize As Integer
Dim fullPages As Integer
Dim leftover As Integer
Dim totalPages As Integer
Dim setNumber As Integer
setSize = 8
currentPage = Me.Page
totalPages = Me.Pages
' Determine which set this page belongs to
setNumber = Int((currentPage - 1) / setSize) + 1
' Figure out how many pages are in this set
If setNumber = Int((totalPages - 1) / setSize) + 1 Then
' Last set - might be shorter
m_PagesInSet = totalPages - ((setNumber - 1) * setSize)
Else
m_PagesInSet = setSize
End If
' Determine page number within the set
m_PageInSet = ((currentPage - 1) Mod setSize) + 1
End Sub
Replace GroupHeader0 with the actual name of your group header section (check the section bar for the correct name or look at the properties).
Thanks a lot. I tried this but all the pages were simply reading Page 1I have just become a fan of ChatGpt and posed your question there. Here is their answer. I have not tried this out but thought I would share it as it looks like less coding.
Here's how to reset page numbers by group:
1. Group Your Report
Make sure your report is already grouped by the desired field:
- Open your report in Design View.
- Use the Group, Sort, and Total pane (bottom of the window) to add grouping if it’s not already present.
2. Set the Page Number Reset
- Click on the Group Header section (e.g., GroupHeader0) in Design View.
- With the header selected, look at the Property Sheet (press F4 if it's not visible).
- Find the property called Force New Page and set it to Before Section (or After Section, depending on layout needs). This ensures each group starts on a new page.
- Still in the Property Sheet, switch to the Event tab (or stay in Format tab depending on Access version).
- Locate the Page Header section of your report.
- Now go to the Group Header section again, and in its On Format event, add the following VBA code:
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
Me.Page = 1
End Sub
Notes:
- You need to make sure your Page Number control is located in the Page Header or Page Footer section.
- This works best when each group starts on a new page, which avoids confusion with overlapping pagination.
I am not sure i understand where these codes go into?So, you're looking for something like this:
Group 1: Pages 1–8 | Labeled: 1–8
Group 2: Pages 9–16 | Labeled: 1–8
Group 3: Pages 17–24 | Labeled: 1–8
If so, let's call each collection of pages a SET and create these variables in your report's VBA (view code)
Private m_PageInSet As Integer
Private m_PagesInSet As Integer
Next, add a footer to the page of the report...
="Page " & m_PageInSet & " of " & m_PagesInSet
In the report page header, add this...
Code:Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer) Dim currentPage As Integer Dim setSize As Integer Dim fullPages As Integer Dim leftover As Integer Dim totalPages As Integer Dim setNumber As Integer setSize = 8 currentPage = Me.Page totalPages = Me.Pages ' Determine which set this page belongs to setNumber = Int((currentPage - 1) / setSize) + 1 ' Figure out how many pages are in this set If setNumber = Int((totalPages - 1) / setSize) + 1 Then ' Last set - might be shorter m_PagesInSet = totalPages - ((setNumber - 1) * setSize) Else m_PagesInSet = setSize End If ' Determine page number within the set m_PageInSet = ((currentPage - 1) Mod setSize) + 1 End Sub