Code Samples for Businesses, Schools & Developers

Last Updated 21 Dec 2017

If you use grouping in a report, you may wish to restart the page numbering for each group

To do so:
1.   add an unbound control ctlGrpPages in the page footer section
2.   use the following code in your report

CODE:

Dim GrpArrayPage(), GrpArrayPages()
Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
Dim GrpPage As Integer, GrpPages As Integer

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

  Dim i As Integer

 If Me.Pages = 0 Then
    ReDim Preserve GrpArrayPage(Me.Page + 1)
    ReDim Preserve GrpArrayPages(Me.Page + 1)
    GrpNameCurrent = Me.[Activity Code]

    If GrpNameCurrent = GrpNamePrevious Then

        GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
        GrpPages = GrpArrayPage(Me.Page)

        For i = Me.Page - ((GrpPages) - 1) To Me.Page
            GrpArrayPages(i) = GrpPages
        Next i

    Else

        GrpPage = 1
        GrpArrayPage(Me.Page) = GrpPage
        GrpArrayPages(Me.Page) = GrpPage

    End If

  Else

      Me!ctlGrpPages = "Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)

  End If

  GrpNamePrevious = GrpNameCurrent

End Sub



Colin Riddington           Mendip Data Systems                 Last Updated 21 Dec 2017

Return to Code Samples Page Return to Top