Code for Access Report group page numbers not returning the correct values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Catherine Dooley
    New Member
    • Aug 2010
    • 3

    Code for Access Report group page numbers not returning the correct values

    I'm trying to get an Access report to print the number of pages of the group instead of the number of the whole report. The code I'm using is below. The Debug statement in the middle shows that the array is being built properly but the results on the report show the wrong number of pages in the groups.

    For example, the first group has 5 pages. The array comes out as:
    1, 2
    2, 2
    1, 3
    2, 3
    3, 3
    1, 4
    2, 4
    3, 4
    4, 4
    1, 5
    2, 5
    3, 5
    4, 5
    5, 5

    So it seems to end with the correct values (page 1 of 5, page 2 of 5... page 5 of 5), but when the report prints, it prints Page 1 of 3, Page 2 of 3, Page 3 of 3, Page 4 of 4, and Page 5 of 5.

    The second group is 2 pages long, but it prints Page 1 of 3 and Page 2 of 3.

    Any help would be much appreciated! Thank you!

    Code:
    Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
    'NOT WORKING
    'This code was originally written by James H Brooks.
    'It is not to be altered or distributed, except as part of an application.
    'You are free to use it in any application,
    'provided the copyright notice is left unchanged.
    'Code Courtesy of James H Brooks.
    
        If Me.Pages = 0 Then    
            ReDim Preserve GrpArrayPage(Me.Page + 10)
            ReDim Preserve GrpArrayPages(Me.Page + 10)
            GrpNameCurrent = Me!AG
            If GrpNameCurrent = GrpNamePrevious Then
                GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
                GrpPages = GrpArrayPage(Me.Page)
                    For ThisPage = Me.Page - ((GrpPages) - _1) To Me.Page
                        GrpArrayPages(ThisPage) = GrpPages
    Debug.Print CStr(GrpArrayPage(ThisPage)) + ", " + CStr(GrpArrayPages(ThisPage))
                    Next ThisPage
            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
    Last edited by Stewart Ross; Sep 4 '10, 08:07 PM. Reason: Added code tags to code segment
Working...