T
Terry Lo via AccessMonster.com
I copied code from another of my reports that works into a new report. The page numbering is supposed to restart when the US01 field changes. On my new report is shows "Page 1 of 1" "Page 2 of 2" instead of restarting the numbering. Each should be only one page so each should say "Page 1 of 1". There will be cases where there are more than one page but for now I was trying it this way. The code below is in the page footer with corresponding text boxes. Any thoughts or suggestions?
Option Compare Database
Option Explicit
Dim DB As Database
Dim GrpPages As Recordset
Function GetGrpPages()
' Find the group name.
GrpPages.Seek "=", Me![US01]
If Not GrpPages.NoMatch Then
GetGrpPages = GrpPages![Page Number]
End If
End Function
Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
'Find the group.
GrpPages.Seek "=", Me![US01]
If Not GrpPages.NoMatch Then
' The group is already 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.
GrpPages.AddNew
GrpPages![US01] = Me![US01]
GrpPages![Page Number] = Me.Page
GrpPages.Update
End If
End Sub
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"
End Sub
Option Compare Database
Option Explicit
Dim DB As Database
Dim GrpPages As Recordset
Function GetGrpPages()
' Find the group name.
GrpPages.Seek "=", Me![US01]
If Not GrpPages.NoMatch Then
GetGrpPages = GrpPages![Page Number]
End If
End Function
Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
'Find the group.
GrpPages.Seek "=", Me![US01]
If Not GrpPages.NoMatch Then
' The group is already 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.
GrpPages.AddNew
GrpPages![US01] = Me![US01]
GrpPages![Page Number] = Me.Page
GrpPages.Update
End If
End Sub
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"
End Sub