View Full Version : Problem Counting in report


bbulla
08-21-2009, 06:04 AM
Hi,

I have a report grouped by Municipality. Within each grouping I am counting the # of records in the group, as well as keeping a count for the total # of records in the report.

I do my counting in the Detail_Print event (see code below). When I had this code in the Detail_Format event, I would get the count wrong when a group spanned more than one page. It is now working in the Detail_Printe vent for the group, but the totalCounter for the report always ends up at zero now.

I don't understand why it is always ending up at zero. Any ideas??

Option Compare Database
Dim counter As Integer
Dim totalCounter As Integer

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
counter = counter + 1
totalCounter = totalCounter + 1

End Sub

Private Sub GroupFooter1_Format(Cancel As Integer, FormatCount As Integer)
lblTotal.Caption = "Total Sites for " & Municipality & ": " & CStr(counter)

End Sub

Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
counter = 0

End Sub


Private Sub Report_Open(Cancel As Integer)

End Sub

Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
lblReportTotal.Caption = "(Total # of Sites on this Report: " & CStr(totalCounter) & ")"

End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
totalCounter = 0

End Sub

bbulla
08-21-2009, 07:38 AM
OK, I found a workaround for this. I put the totalCounter back into the Report_Detail event, but since that gives a higher count than there actually is, I subtract from the totalCount in the ReportFooter_Format event. See below. I still don't understand why I can't count in the Report_Print event though.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
totalCounter = totalCounter + 1

End Sub

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
counter = counter + 1

End Sub

Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
totalCounter = totalCounter - (Me.Page - 1) 'use page - 1 because in the Detail_Format it adds one for each page
lblReportTotal.Caption = "(Total # of Sites on this Report: " & CStr(totalCounter) & ")"

End Sub

Rich
08-21-2009, 09:39 AM
A couple of unbound textboxes with the control source set to =1 and the correct use of the RunningSum property for each would have done the same without the need for VBA

BobMcClellan
08-21-2009, 09:51 AM
Amateurs...built the ark.Professionals...built the Titanic
Cool tag line Rich.