Using the Format event procedure to increment a variable or control can be
unreliable if care is not taken. For instance referencing the Pages property
in the report, e.g. to print 'Page # of ##' in the page footer forces two
iterations through the report resulting in double counting, or the Format
event procedure for a section can execute more than once in the same
iteration, with the FormatCount property being 1 each time in some
circumstances, e.g. if a section spans two pages.
Initializing the control or variable to zero in the report header's Format
event Procedure should cure any double counting caused by referencing the
Pages property. Undoing increments in the Retreat event procedure of a
section can get round a section's Format event firing twice during the same
iteration through the report, but can be tricky to control.
Generally speaking the Print event procedure is easier to use and more
reliable for this sort of thing, but has the drawback that the event does not
occur for any pages skipped in print preview by jumping over them by means of
the navigation buttons. If all pages are viewed sequentially in preview or
the complete report sent to a printer then there should be no problem. The
increment should be made conditional on 'If PrintCount = 1 Then'.
Another possibility is not to increment the values in code but to use the
RunningSum property of a hidden control and then reference the hidden control
as the ControlSource property of another control in a footer when you want
to show the accumulated value.
Ken Sheridan
Stafford, England