Sum Doubles

  • Thread starter Thread starter dave h
  • Start date Start date
D

dave h

Hi,

I have a total figure in a group footer. If I print directly to the default
printer, the amount is correct. If I use a custom dialog to allow the user
to select a printer, the amount is correct.

However, if I use the preview option and the user selects the printer using
the standard Windows printer dialog, then the amount is doubled when it
prints - but it is correct when viewed on-screen as the print-preview.

Any help will be appreciated as it is the last option that we want to use
most often. Thanks, Dave H.
 
Any chance that this field is accumulated programmatically, e.g. in the
Print event of the Detail section?

If so, all the events fire again for the print run after they have already
fired for the preview, and so the total is double what it should be. You can
solve that by resetting the variable to zero in the Report Header section's
Format event.

Even it that solves your immediate problem, using the report events to
accumulate a total across several pages is unreliable. For example, if you
only print pages 5-7 of the report, the events for the missing pages may not
fire, and so the total will be wrong. So, if possible, create the calculated
field in the query the report is based on, and use a Running Sum text box to
accumulate it.
 
I agree with Allen. Creating totals/sums in code is very rarely required. I
have created hundreds of reports over the past ten years and I don't recall
ever having to use code in a report to aggregate values.

If you describe what you are doing, maybe someone could suggest an
alternative.
 
Hi Allen,

Thanks for the info - yes, the field was accumulated programmatically. The
SQL is fairly complicated and involves Inner and Outer Joins. I was having
a lot of trouble getting the "Customer" total to work, as there is a detail
line that does not contribute to this total. The code solution was quick
and easy - except for this doubling effect.

Following your advice, I looked for Format Event for the Report Header
Section - but I don't seem to have such an event. However, I tried both the
PageHeader0_Format and the CustomerID Header events to zero out the
accumulator. Either of these seems to work but have not done much testing.

I don't create many reports, so I'm pretty much a novice in this area. Here
is a rough outline of my report:

-A Page Header that contains some boiler plate stuff
-A CustomerID Header that Customer ID and associated data
-An Item Header that contains product info including the price that is to be
accumulated
-A Detail line that contains a packing list associated with the above item -
the data for this set of lines and the item header are in the same row
retrieved by the SQL - but no price should be accumulated for these lines
-An Item Footer that just has a horizontal line
-A CustomerID Footer that displays the accumulated total
-A Page Footer with some dates and boilerplate stuff

It seems logical to me that zeroing out in the CustomerID Header is the
logical place to do this as the total is being printed out in the customerID
Footer. Am I thinking correctly? Any other suggestions?

Thanks, DaveH
 
If you want to clear the value per customer and start accumulating the value
for the next customer again, then resetting the variable in the CustomerID
Header section makes perfect sense.

Resetting the variable in the Page Header's Format event would only be a
good idea of you were trying to accumulate a total for the page.

The alternative to relying on the event it to add a text box with these
properties:
ControlSource: your calculation, e.g. =[Quantity] * [UnitPrice]
Running Sum: Over Group
 
Back
Top