Option Compare Database
Option Explicit
'Define variables in module header so they persist through multiple execution of form events.
Private PTSum As Currency
Private CCSum As Currency
Private Sub DateFooter_Format(Cancel As Integer, FormatCount As Integer)
'' only add the first time the format event runs for this section
'' The format event must run multiple times if Access has trouble breaking at the end of the page because of overflow.
'' FormatCount increments each time the Retreat event runs.
If FormatCount = 1 Then
PTSum = PTSum + Nz(Me.srptProductType.Report!DateFooterSum, 0)
CCSum = CCSum + Nz(Me.srptCostCenter.Report!DateFooterSum, 0)
End If
Debug.Print Format(PTSum, "Currency") & " --- " & Format(CCSum, "currency") & " --- " & Format(PTSum + CCSum, "Currency")
End Sub
Private Sub Report_Open(Cancel As Integer)
PTSum = 0
CCSum = 0
End Sub
Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
Me.txtGrandTotal = PTSum + CCSum
'' reset accumulation. Otherwise on print preview, the total will just keep incrementing
PTSum = 0
CCSum = 0
End Sub