loony looping of Report events

G

Guest

I am confused by what Access is doing when reports open. It seems to call
some event routines twice as often as it should, and worse.

I have a report that is opened by a form using:

DoCmd.OpenReport ShowKitsReport, acPreview, GetFilteredKits

where GetFilteredKits is the name of a query that returns the records I want
to display. This report opens a companion report (ShowKitsBOMsReport). If
these reports were already opened, they are first closed.

I initially tried opening the report without a filter parameter, then
applying filters after the report opened, plus other ignorant efforts, until
I realised how easy it was to do it this way. Everything works, but, while
debugging, I found weird things happening. Here is the sequence of event
routines (when the query returns 9 records to the report):

1/ Sub Report_Close() called for ShowKitsReport
2/ Sub Report_Close() called for ShowKitsBOMsReport
3/ Sub Report_Activate() called for ShowKitsReport; opens
ShowKitsBOMsReport
4/ Sub Report_Open() called for ShowKitsBOMsReport; record source is set
5/ Sub Report_Activate() called for ShowKitsBOMsReport; no code here
6/ Sub Report_Activate() ends for ShowKitsReport
7/ Sub PageHeaderSection_Format called 1X for ShowKitsReport; unbound
controls receive values
8/ Sub Detail_Format called 9X; no code here
9/ Sub PageHeaderSection_Format called 1X for ShowKitsReport; unbound
controls receive values
10/ Sub Detail_Format called 9X
11/ Sub Report_Activate() called 3X; each time, it is aborted by logic to
prevent reloading companion report and causing an infinite loop of event
routines.

The reports both turn out OK, but the above sequence suggests that things
aren't exactly kosher.

Am I inadvertently creating traps for myself here, or is such apparently
goofy behaviour intrinsic to the process?
 
M

Marshall Barton

Allen_N said:
I am confused by what Access is doing when reports open. It seems to call
some event routines twice as often as it should, and worse.

I have a report that is opened by a form using:

DoCmd.OpenReport ShowKitsReport, acPreview, GetFilteredKits

where GetFilteredKits is the name of a query that returns the records I want
to display. This report opens a companion report (ShowKitsBOMsReport). If
these reports were already opened, they are first closed.

I initially tried opening the report without a filter parameter, then
applying filters after the report opened, plus other ignorant efforts, until
I realised how easy it was to do it this way. Everything works, but, while
debugging, I found weird things happening. Here is the sequence of event
routines (when the query returns 9 records to the report):

1/ Sub Report_Close() called for ShowKitsReport
2/ Sub Report_Close() called for ShowKitsBOMsReport
3/ Sub Report_Activate() called for ShowKitsReport; opens
ShowKitsBOMsReport
4/ Sub Report_Open() called for ShowKitsBOMsReport; record source is set
5/ Sub Report_Activate() called for ShowKitsBOMsReport; no code here
6/ Sub Report_Activate() ends for ShowKitsReport
7/ Sub PageHeaderSection_Format called 1X for ShowKitsReport; unbound
controls receive values
8/ Sub Detail_Format called 9X; no code here
9/ Sub PageHeaderSection_Format called 1X for ShowKitsReport; unbound
controls receive values
10/ Sub Detail_Format called 9X
11/ Sub Report_Activate() called 3X; each time, it is aborted by logic to
prevent reloading companion report and causing an infinite loop of event
routines.

The reports both turn out OK, but the above sequence suggests that things
aren't exactly kosher.

Am I inadvertently creating traps for myself here, or is such apparently
goofy behaviour intrinsic to the process?


Report sections are processed as many times and in whatever
order is necessary to produce the specified result.

When you specify section and/or group KeepTogether,
especially in conjunction with CanGrow and/or CanShrink, the
Format and Print events of several sections might be
re-evaluated several times.

The use of the Pages property in a text box will double the
report's processing.

Previewing a report, will re-evaluate sections as you
navigate around the report's pages.

Printing the report from the Preview window will re-evaluate
the report from the beginning.

Bottom line: The behavior is not goofy (once you understand
what is going on) and you will have to find another way to
get the desired results. Have you tried using subreports
instead of separate reports?
 
G

Guest

Thanks, Marshall.

I will accept this a 'normal' behaviour and not mess around with the code,
then.

Marshall Barton said:
... Have you tried using subreports instead of separate reports?

The master form also provides for export of the two reports to Excel (with
subsequent modificaton by ActiveX), for delivery to different people, so I
thought I had no choice but to use separate reports.

Cheers!
 
M

Marshall Barton

Allen_N said:
I will accept this a 'normal' behaviour and not mess around with the code,
then.



The master form also provides for export of the two reports to Excel (with
subsequent modificaton by ActiveX), for delivery to different people, so I
thought I had no choice but to use separate reports.


You might or might not be right about not using subreports
when you export to Excel, I haven't tried that. (I found it
was usually more robust to export the report's record source
query instead of the formatted report.)
 
G

Guest

That sounds like an idea. How do you do it?

Marshall Barton said:
You might or might not be right about not using subreports
when you export to Excel, I haven't tried that. (I found it
was usually more robust to export the report's record source
query instead of the formatted report.)
 
M

Marshall Barton

Allen_N said:
That sounds like an idea. How do you do it?


I think there are lots of was to export a query, The File -
Export menu item, the Tools - Analyze with Excel menu item
and the TransferSpreadsheet method come to mind.

Unfortunately, a law suit a year or two back resulted in
removing several programtic approaches such as using an
Append query.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top