sub report Code

  • Thread starter Thread starter Kevinm
  • Start date Start date
K

Kevinm

I have report with a sub report, that has some code in it to calculate
totals. I have the code set to run on load. This works fine if I load the
sub report all by it self. But when I load the master report with the sub
report as part of it, my code does not fire. on what event do I need to set
my code to have it run??

<my code bits>
Private Sub Report_Current()
Dim RafPP As Integer
Dim DoorPP As Integer

Dim runtot As Integer
Dim Don As Integer

Don = Donation.Value


If RafflePrePaid.Value = 1 Then
RafPP = 0
Else: RafPP = RaffleTickets.Value
End If
If DoorPrePaid.Value = 1 Then
DoorPP = 0
Else: DoorPP = AuctionDoorFee.Value
End If
runtot = Don + DoorPP + RafPP
runningTotal.Value = runtot
End Sub
 
Kevin:

You say your code runs when the subreport loads and the code you quote
appears to run from the report's "current" event. In my version of Access
(2002), a report doesn't have load or current events. I'm wondering if
you've written a report or a form.

If you have indeed written a report with a subreport, it seems you should
accumulate the SubReport's running total in the Print event procedure for
the SubReport's Detail Section. (The Print event only occurs for rows that
will be printed. You only want to accumulate data for printed rows, which is
why you use the Print event.)

You need to capture the running-total data when the PrintCount property is
1. (The print event procedure may get called more than once when a section
is printed, eg if the section prints across two pages. Each time the Print
event procedure is called for the same section, the PrintCount property is
incremented. For any given row in the record source, you don't want to add
data to the running total more than once, which is why you capture data only
when the PrintCount is 1.)

Here's some sample code for the Print event procedure of the SubReport:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Dim RafPP As Integer
Dim DoorPP As Integer
Dim runtot As Integer
Dim Don As Integer

Don = Donation.Value
If PrintCount = 1 Then
If RafflePrePaid.Value = 1 Then
RafPP = 0
Else
RafPP = RaffleTickets.Value
End If
If DoorPrePaid.Value = 1 Then
DoorPP = 0
Else
DoorPP = AuctionDoorFee.Value
End If
runtot = Don + DoorPP + RafPP
runningTotal.Value = runtot
End If

End Sub

I don't know whether you have linked a master and child field between the
main report and subreport. If you have that might give you other options.

Regards
Geoff
 
Back
Top