A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA Code For Page Numbering Not Working



 
 
Thread Tools Display Modes
  #1  
Old August 3rd, 2007, 05:29 AM posted to microsoft.public.access.reports
[email protected][_2_]
external usenet poster
 
Posts: 8
Default VBA Code For Page Numbering Not Working

Hi all, I used the code from the foll wing Microsoft page to set up
numbering by group within a report (in Page x of y format for each
group):

http://support.microsoft.com/kb/306127/

It worked fine in their sample database, but in my database, the total
pages is coming up blank. After sticking a few message boxes in teh
code to see what wasn't executing, it appears the code in this if
statement does not get called for some reason:

** If Not GrpPages.NoMatch Then

GetGrpPages = GrpPages![Page Number]
MsgBox "Call Function"

End If
***

Any ideas on what is messing this up would be very much appreciated.
Here is the full code:



Dim DB As Database
Dim GrpPages As Recordset

Option Compare Database ' Use database order for string comparisons.
Option Explicit ' Requires variables to be declared before they are
used.


Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As
Integer)
' Set page number to 1 when a new group starts.

Page = 1

End Sub


Function GetGrpPages()

' Find the group name.

GrpPages.Seek "=", Me![SubEvent]

MsgBox Me![SubEvent]

If Not GrpPages.NoMatch Then

GetGrpPages = GrpPages![Page Number]
MsgBox "Call Function"

End If

End Function

Private Sub Report_Open(Cancel As Integer)

Set DB = DBEngine.Workspaces(0).Databases(0)

DoCmd.SetWarnings False

DoCmd.RunSQL "Delete * From [Category Group Pages];"

DoCmd.SetWarnings True

Set GrpPages = DB.OpenRecordset("Category Group Pages",
DB_OPEN_TABLE)

GrpPages.Index = "PrimaryKey"
MsgBox "Report Opend"

End Sub


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

' Find the group.
MsgBox "Find Group Started"

GrpPages.Seek "=", Me![SubEvent]

If Not GrpPages.NoMatch Then

' The group is already there.
MsgBox "Group There"

If GrpPages![Page Number] Me.Page Then

GrpPages.Edit

GrpPages![Page Number] = Me.Page

GrpPages.Update

End If


Else

' First page of group, so add it.
MsgBox "Group NOT there"

GrpPages.AddNew

GrpPages![SubEvent] = Me![SubEvent]

GrpPages![Page Number] = Me.Page

GrpPages.Update

End If

End Sub

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:09 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.