P
PowerLifter1450
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
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