By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

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

P: 3
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!

Expand|Select|Wrap|Line Numbers
  1. Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
  2. 'NOT WORKING
  3. 'This code was originally written by James H Brooks.
  4. 'It is not to be altered or distributed, except as part of an application.
  5. 'You are free to use it in any application,
  6. 'provided the copyright notice is left unchanged.
  7. 'Code Courtesy of James H Brooks.
  8.  
  9.     If Me.Pages = 0 Then    
  10.         ReDim Preserve GrpArrayPage(Me.Page + 10)
  11.         ReDim Preserve GrpArrayPages(Me.Page + 10)
  12.         GrpNameCurrent = Me!AG
  13.         If GrpNameCurrent = GrpNamePrevious Then
  14.             GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
  15.             GrpPages = GrpArrayPage(Me.Page)
  16.                 For ThisPage = Me.Page - ((GrpPages) - _1) To Me.Page
  17.                     GrpArrayPages(ThisPage) = GrpPages
  18. Debug.Print CStr(GrpArrayPage(ThisPage)) + ", " + CStr(GrpArrayPages(ThisPage))
  19.                 Next ThisPage
  20.         Else
  21.             GrpPage = 1
  22.             GrpArrayPage(Me.Page) = GrpPage
  23.             GrpArrayPages(Me.Page) = GrpPage
  24.         End If
  25.     Else
  26.         Me!ctlGrpPages = "Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
  27.     End If
  28.     GrpNamePrevious = GrpNameCurrent
  29.  
  30. End Sub
Aug 30 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.