subtotals doubled if printing report after preview

G

Glenn

hi all,

as the subject states, my problem lies with incorrect subtotals on
report printed after they are previewed. (access 2000)

the subtotals are the result of a custom function

simplified report event description:

in: report_open

n_sum = 0

in: detail_print
n_sum = n_sum + f_calc_Sum(params)
'calc sum depends on diff. parameters - not straightforward sums

---------
this works fine if the report is directly printed. if previewed, and the
user is so kind to go throught every page incrementally, it is fine
also.

but if the report is printed after the user has previewed it, access
goes through every sum again. the result is doubled intermediate & end
sums.
--------
i've searched for a way to detect the print command and reset the
variable n_sum, but was unsuccesful.

searching on usenet showed many similar questions, but with no
convenient answers.
My report is too complex (and finally works;) to modify its structure
significantly (other queries/temp. tables and such)

I do not understand how the PrintCount parameter, suggested by some,
could help. the help states that it is reset each time a new section is
printed. so losing any link to a previous situation.

Now, my only real solution is to present the user a (hopefully) clear
warning not print after previewing.

come on, you can do better :)
glenn
 
A

Allen Browne

This kind of accumulation is not reliable. If the user previews page 1, and
jumps to page 4, the events may not fire for the intervening pages, and so
the results will be wrong.

Alternatives:
1. Use a Running Sum.

2. Create a query as the source for the report, and put your function into
the query as a calculated field.

If you want to go with your original idea anyway, move the line:
n_sum = 0
into the Format event of the Report Header, instead of the Open event of the
report. If you do not have a Report Header section, create one (View menu).
 
G

Glenn

This kind of accumulation is not reliable. If the user previews page 1, and
jumps to page 4, the events may not fire for the intervening pages, and so
the results will be wrong.
yes, you're right. But I accepted it to get the flexibility I needed in
my report.
Alternatives:
1. Use a Running Sum.
I tried this, but for some reason it didn't work as I expected.
2. Create a query as the source for the report, and put your function into
the query as a calculated field.
I've tried this also, but again I chose my method.
yes I'm stubborn :)
If you want to go with your original idea anyway, move the line:
n_sum = 0
into the Format event of the Report Header, instead of the Open event of the
report. If you do not have a Report Header section, create one (View menu).
That resolve the print after preview issue. Great!
The exact chain of events is not all that clear to me. I'll look into
that again (sigh).

thanks for your help
glenn
 
A

Allen Browne

Report_Open fires once, when the report opens, before the data is retrieved.

The Format event of the Report Header fires when Access prepares a print or
preview. Since this is always the first section on a report, it is the one
to use to reset your accumulation variable.
 
Top