With the addition code, and 3 pages of records. The first page totals
show as credits of the second page. Second and third page are correct
totals.
The immediate window show:
Page=1 PrintCount=1 x=0 RentRunSum=24797.5
Page=2 PrintCount=1 x=24797.5 RentRunSum=28697.5
Page=1 PrintCount=1 x=28697.5 RentRunSum=24797.5
Page=2 PrintCount=1 x=24797.5 RentRunSum=28697.5
Page=1 PrintCount=1 x=0 RentRunSum=24797.5
Page=2 PrintCount=1 x=24797.5 RentRunSum=29697.5
Page=1 PrintCount=1 x=0 RentRunSum=24797.5
Page=2 PrintCount=1 x=24797.5 RentRunSum=29697.5
Page=3 PrintCount=1 x=29697.5 RentRunSum=29722.5
Page=1 PrintCount=1 x=29722.5 RentRunSum=24797.5
Page=2 PrintCount=1 x=24797.5 RentRunSum=29697.5
Page=3 PrintCount=1 x=29697.5 RentRunSum=29722.5
My code is
Option Compare Database
Dim x As Currency
Dim y As Currency
Dim z As Currency
Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As
Integer)
End Sub
Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As
Integer)
Debug.Print "Page=" & Me.Page & " PrintCount=" _
& PrintCount & " x=" & x & " RentRunSum=" & Me!RentRunSum
RentPageSum = RentRunSum - x
OtherPageSum = OtherRunSum - y
SDPageSum = SDRunSum - z
x = RentRunSum
y = OtherRunSum
z = SDRunSum
End Sub
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No checks on that date", _
vbOKOnly + vbInformation, _
"No Matching Records"
Cancel = True
End Sub
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As
Integer)
End Sub
Private Sub ReportHeader_Print(Cancel As Integer, PrintCount As
Integer)
x = 0
y = 0
z = 0
End Sub
Man, was this ever a tough one. It took me quite a while to
reproduce the issue by varying my report's setting for
KeepTogether and skipping around pages in the report's
preview. The core issue is that the Page Print event
doesn't always fire unless I preview the pages in sequential
order or jumped directly to the last page. Don't ask me to
explain the logic behind what's happening, but I think it's
a matter of not executing some(?) events on the pages that
are not being displayed.
Regardless of how/why it happens, I think this will work
reliably, at least it did in my tests. Get rid of all the
code you have for this and use this instead:
Private Sub PageFooter_Format(Cancel As Integer, FormatCount
As Integer)
Static curRent(100) As Currency
Static curOther(100) As Currency
Static curSD(100) As Currency
curRent(Me.Page) = Me!RentRunSum
RentPageSum = curRent(Me.Page) - curRent(Me.Page - 1)
curOther(Me.Page) = Me!OtherRunSum
OtherPageSum = curOther(Me.Page) - curOther(Me.Page - 1)
curSD(Me.Page) = Me!SDRunSum
SDPageSum = curSD(Me.Page) - curSD(Me.Page - 1)
End Sub
Note there is no ReportHeader event code and the use of the
Format event instead of the Print event. The array
dimension of 100 is any number larger than the most pages
the report may ever have.
Good luck and be sure to let me know if you still have
trouble with this.