report preview different than printout when calculating totals

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Any ideas how to get a report to print the same thing it displays when in
print preview? I am calculating totals in code:

Private Function GetGroupTotal1() As String 'SubGroup
On Error GoTo Err_Handler

GetGroupTotal1 = dblCostSum1
txtHoursSum1 = dblHoursSum1

' Reset the variable to 0 for next group.
dblCostSum1 = 0
dblHoursSum1 = 0

Exit_Here:
Exit Function

Err_Handler:
MsgBox Err.Description
Resume Exit_Here

End Function

I have a text box in the group footer that calls GetGroupTotal1 (). Both
GetGroupTotal1 & txtHoursSum1 are calculating properly in print preview, but
when I send the report to the printer, it adds the detail totals for the next
record to the previous groups totals.
 
Holly said:
Any ideas how to get a report to print the same thing it displays when in
print preview? I am calculating totals in code:

Private Function GetGroupTotal1() As String 'SubGroup
On Error GoTo Err_Handler

GetGroupTotal1 = dblCostSum1
txtHoursSum1 = dblHoursSum1

' Reset the variable to 0 for next group.
dblCostSum1 = 0
dblHoursSum1 = 0

Exit_Here:
Exit Function

Err_Handler:
MsgBox Err.Description
Resume Exit_Here

End Function

I have a text box in the group footer that calls GetGroupTotal1 (). Both
GetGroupTotal1 & txtHoursSum1 are calculating properly in print preview, but
when I send the report to the printer, it adds the detail totals for the next
record to the previous groups totals.

My guess is that its the event you are using to generate this code. The
Format event (for example) can actually be called multiple times. Check
out the timing of the Format and Print events in the help. It
specifically mentions totals and how you might have to back it out.

Your function here is also referencing your dblCostSum1, which I can
only assume is a global variable that you are setting elsewhere.

The question is, why are you doing it this way instead of using
=Sum([FieldName]) as your calculated control? Is there something
specific to the way you are generating the value for dblCostSum1?
 
I am not using any event to fill these totals, I have a textbox in a group
level that calls this function. I cannot use the Sum() function because I
have a subreport within the same group level that has totals that need to be
included in some of the totals

Duncan Bachen said:
Holly said:
Any ideas how to get a report to print the same thing it displays when in
print preview? I am calculating totals in code:

Private Function GetGroupTotal1() As String 'SubGroup
On Error GoTo Err_Handler

GetGroupTotal1 = dblCostSum1
txtHoursSum1 = dblHoursSum1

' Reset the variable to 0 for next group.
dblCostSum1 = 0
dblHoursSum1 = 0

Exit_Here:
Exit Function

Err_Handler:
MsgBox Err.Description
Resume Exit_Here

End Function

I have a text box in the group footer that calls GetGroupTotal1 (). Both
GetGroupTotal1 & txtHoursSum1 are calculating properly in print preview, but
when I send the report to the printer, it adds the detail totals for the next
record to the previous groups totals.

My guess is that its the event you are using to generate this code. The
Format event (for example) can actually be called multiple times. Check
out the timing of the Format and Print events in the help. It
specifically mentions totals and how you might have to back it out.

Your function here is also referencing your dblCostSum1, which I can
only assume is a global variable that you are setting elsewhere.

The question is, why are you doing it this way instead of using
=Sum([FieldName]) as your calculated control? Is there something
specific to the way you are generating the value for dblCostSum1?
 
Holly said:
I am not using any event to fill these totals, I have a textbox in a group
level that calls this function. I cannot use the Sum() function because I
have a subreport within the same group level that has totals that need to be
included in some of the totals

Then the same thing I mentioned before about the Format/Print events
firing twice still holds true. The function is probably getting called
numerous times, which is doubling your values.
 
The values are not doubling, the first value of the next record after the
subtotaling is getting adding to the previous subtotal. I put a stop on the
code that is doing the calculations and it only stops once.
 
Holly said:
The values are not doubling, the first value of the next record after the
subtotaling is getting adding to the previous subtotal. I put a stop on the
code that is doing the calculations and it only stops once.

I'm not sure I can help you any further. Looking at the example code
that you've provided, I'm only seeing part of the whole process.

Let me try and understand.
You've put a textbox in the groupfooter and set it's source equal to
GetGroupTotal1(). And you want it to determine what the value of
dblCostSum1 is and display it?

That part I can trace through your code. What I'm not seeing is how you
are incrementing the value of dblCostSum1. Based on your description,
it's gotta be happening in the detail section.

This is why I made my original comments based on using the report
events. I thought you were using the Detail_Format event (or print
event) to increase the value of dblCostSum1 with each record.

There's more to your process and I need some additional information,
specifically related to where/how you are incrementing the value of
dblCostSum1

On a side note, you should consider changing:
GetGroupTotal1 = dblCostSum1
to
GetGroupTotal1 = CStr(dblCostSum1)

since you've designed your Function to return a string but you're
assigning a double to it. Access will convert it to a string on its own
(because it has to), but you can convert it first yourself, which makes
everything cleaner.
 
I am incrementing the group totals in the Detail section using the
Detail_Print event. I am setting the value of the total printed (and zeroing
out the group total) using GroupTotal1() in the group total sections. I have
five grouping levels using this process. Hopefully this clears thing up.
 
Holly said:
I am incrementing the group totals in the Detail section using the
Detail_Print event. I am setting the value of the total printed (and zeroing
out the group total) using GroupTotal1() in the group total sections. I have
five grouping levels using this process. Hopefully this clears thing up.

I think maybe you could checkout an earlier post on a similar nature by
Allen Browne:
http://groups.google.com/group/micr...+multiple+times&rnum=4&hl=en#2a1b5a2aa83e79da
Allen Browne (#2):
http://groups.google.com/group/comp...nt+event+totals&rnum=1&hl=en#a89ef94d61e51c6a

He discusses using the Format and Print events for calculating totals
and how they could be incorrect. You could also put a debug.print
statement into your code to see what events are firing when, and what
the values are.. this could help you track down why the totals are
incorrect.
 
Back
Top