PDA

View Full Version : Solved: Report Last Page Not Correct



lawsonbooth
03-30-2010, 07:07 AM
I have a report where I have to track some totals which have calculation criteria to complex for me to handle with “IIF” statements in the print controls so I use VBA to perform the calculations. The report works fine until it gets to the last page of the report. The last section totals and report grand totals are wrong. I have been researching the posts and reading everything I can find on the PrintEvent and I think it has something to do with the way Access backs up to format a page. I am totally baffled. :banghead: Any help to get the last page to print correctly would be greatly appreciated. I can not post the database because it contains sensitive company data.

I am using Access'97 on a Windows XP platform.

Here are the various code sections from the report:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then

[tbSavedYrPrem] = 0

xDateItems = xDateItems + 1
xEmpItems = xEmpItems + 1

'ignore 000 & 045
If [tbDispositionCode] <> "000" And _
[tbDispositionCode] <> "045" Then

'count completes
If [tbTaskStatus] = "Completed" Then
xDateCount = xDateCount + 1
xEmpCount = xEmpCount + 1
End If

'count saved
If ([tbDispositionCode] >= "001" And _
[tbDispositionCode] <= "033") Or _
([tbDispositionCode] = "046") Then
'detail
[tbSavedYrPrem] = [xYrPrem]
'accum date level
xDateSaved = xDateSaved + Nz([xYrPrem])
'accum emp level
xEmpSaved = xEmpSaved + Nz([xYrPrem])
End If

End If

End If
End Sub

Private Sub GroupFooter1_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then
'emp level
'[tbEmpItems] = xEmpItems
[tbEmpCount] = xEmpCount
[tbEmpSaved] = xEmpSaved
xEmpItems = 0
xEmpCount = 0
xEmpSaved = 0
End If
End Sub

Private Sub GroupFooter3_Print(Cancel As Integer, PrintCount As Integer)
If PrintCount = 1 Then
'date level
[tbDateSaved] = xDateSaved
[tbDateCount] = xDateCount
'[tbDateItems] = xDateItems
xDateCount = 0
xDateSaved = 0
xDateItems = 0
End If
End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
xDateCount = 0
xDateSaved = 0
xDateItems = 0
xEmpItems = 0
xEmpCount = 0
xEmpSaved = 0
End Sub

OBP
03-31-2010, 04:02 AM
Have you tried using the ON Format event instead of the Print event?
Are the grand totals OK in print Preview?

lawsonbooth
03-31-2010, 07:24 PM
OBP, thank you for helping. To answer your questions:

1. I move the calculations to the format section.

2. The grand totals are not correct in preview.

Moving the calculations to the format event made the section totals correct, but grand total is not correct (xEmpCount).

We are closer, any other ideas?

Lawson

OBP
04-01-2010, 04:57 AM
Are the Grand Totals based on VBA or just totalling the other Fields?

lawsonbooth
04-01-2010, 05:37 AM
The grand total which is field xEmpCount is done with VBA only. Should I condition the activities in the footer sections with a test for formatcount = 1?

Lawson

OBP
04-01-2010, 07:05 AM
I would certainly try it.

lawsonbooth
04-05-2010, 11:27 AM
OBP, I really appreciate you looking at my problem. Due to a project deadline I had to re-write the report and got it working without using any VBA. Thanks again for your time and help.