oops ... sorry, Marsh. I thought you had seen the code at
http://support.microsoft.com/kb/841779/en-us.
Following that link, I created a table in the FE:
Table Name: CategoryGroupPages
Field Name: DapID
Data Type: Long
Indexed: Yes (No Duplicates)
Field Name: PageNumber
Date Type: Number
Field Size: Long
PrimaryKey: DapID
< then, the following procedures in the report module:>
Option Compare Database
Option Explicit
Dim DB As Database
Dim GrpPages As Recordset
Private Sub Report_Open(Cancel As Integer)
Set DB = DBEngine.Workspaces(0).Databases(0)
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete * From [CategoryGroupPages];"
DoCmd.SetWarnings True
Set GrpPages = DB.OpenRecordset("CategoryGroupPages", DB_OPEN_TABLE)
GrpPages.Index = "PrimaryKey"
End Sub
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![DapID]
If Not GrpPages.NoMatch Then
GetGrpPages = GrpPages![PageNumber]
End If
End Function
Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
'Find the group.
GrpPages.Seek "=", Me![DapID]
If Not GrpPages.NoMatch Then
'The group is already there.
If GrpPages![PageNumber] < Me.Page Then
GrpPages.Edit
GrpPages![PageNumber] = Me.Page
GrpPages.Update
End If
Else
'This is the first page of the group. Therefore, add it.
GrpPages.AddNew
GrpPages![DapID] = Me![DapID]
GrpPages![PageNumber] = Me.Page
GrpPages.Update
End If
End Sub
<end code>
Three text boxes are created in the page footer:
Text box: -----------------------------
Name: GroupXY
ControlSource: =GetGrpPages()
Visible: No
Text box: ------------------------------
Name: ReferToPages
ControlSource: =Pages
Visible: No
Text box: ------------------------------
Name: Text154
ControlSource: ="Page " & [Page] & " of " & [GroupXY]
Visible: Yes
Text box: ------------------------------
Name: Text190
ControlSource: =Page
Visible: No
<To make certain controls in the page footer visible/invisible, I used the
following procedure (using just one control as an example):>
Private Sub PageFooter_Print(Cancel As Integer, PrintCount As Integer)
Select Case Me!GroupXY 'GroupXY is total pages for the Group
Case Is = 1 'Group requires single page
Me!Line32.Visible = True
Case Is > 1 'Group requires multiple pages
Select Case Me!Text190 'Designates which page we're on
Case Is <> Me!GroupXY 'Not the last page
Me!Line32.Visible = False
Case Is = Me!GroupXY 'Is the last page
Me!Line32.Visible = True
End Select
End Select
End Sub
<end code>
.......... If within the page header's OnPrint (or OnFormat) event I try to
reference the text boxes in the page footer (GroupXY, ReferToPages, Text154,
and Text190), the result is not as expected -- the group page numbers
displayed in the page header section do not match the numbers displayed in
the page footer.
I thought maybe I could use the same process in the page header section for
re-numbering pages that I used in the page footer section, but this would
entail ForceNewPage *Before* the Group section (as well as after it) --
which would be undesirable.
Mark