On Open event does not fire when doing DoCmd.OpenReport in normal

M

Mark VII

Greetings --

I'm working on mechanizing the generation of a slate of reports. Some of
them are the same report, but run multiple times with different selection
criteria. I build the report selection string in the OnOpen event for the
report. This works fine if I'm bringing the report up in preview mode via
either the Access UI or via VBA. However, if I do a DoCmd.Openreport in
normal view via VBA, the OpenReport event does not fire. Consequently, I
don't get the desired selecton criteria.

Any suggestions?

Thanks,
Mark
 
A

Allen Browne

The report's Open event should fire when you OpenReport in acViewNormal,
unless it is already open.

I take it you are using the report's Open event to pop up a dialog and
collect criteria from the user. If you can't get that to work, 2 alternative
approaches are to:
a) Use a form where the user supplies the critiera, and apply them via the
WhereCondition of OpenReport, or
b) Use the report's query to supply the criteria.

Examples of the first:
http://allenbrowne.com/casu-08.html
http://allenbrowne.com/casu-15.html
 
M

Mark VII

Hi Allen --
The report's Open event should fire when you OpenReport in acViewNormal,
unless it is already open.

That's what's so crazy about this. The report is not already open, yet the
Open event does not fire. (I determined this by setting a breakpoint in my
Open event code.)
I take it you are using the report's Open event to pop up a dialog and
collect criteria from the user. If you can't get that to work, 2 alternative
approaches are to:
a) Use a form where the user supplies the critiera, and apply them via the
WhereCondition of OpenReport, or
b) Use the report's query to supply the criteria.

Actually, it's sort of involved. This report runs 12 times, using different
subsets of data each time. The list of subset values resides in a lookup
table. The VBA that opens the report loops through the list of values and
sets some public variables. The report's Open event reads the variables,
builds SQL and sets the report's RecordSource property. Without the Open
event firing, the data source doesn't get set.

FWIW, here's how I ended up working around the problem.

-- Open the report in preview mode. (The Open event fires here, so the
RecordSource gets built and set OK.
-- Use DoCmd.Printout to send the report to the output device.
-- Use DoCmd.Close to close the repot.

Not pretty, but it works.

Thanks for the suggestions.

Mark
 
D

Dirk Goldgar

In
Mark VII said:
Greetings --

I'm working on mechanizing the generation of a slate of reports.
Some of them are the same report, but run multiple times with
different selection criteria. I build the report selection string in
the OnOpen event for the report. This works fine if I'm bringing the
report up in preview mode via either the Access UI or via VBA.
However, if I do a DoCmd.Openreport in normal view via VBA, the
OpenReport event does not fire. Consequently, I don't get the
desired selecton criteria.

The Open event ought to fire, even when you open the report in normal
view. Are you sure it's the Open event you're using, not the Activate
event? Are you sure you have the report's "OnOpen" property set to
"[Event Procedure]"? Could there be a fault of some kind in your code,
that is causing it not to execute?
 
M

Mark VII

Hi Dirk --
The Open event ought to fire, even when you open the report in normal
view. Are you sure it's the Open event you're using, not the Activate
event? Are you sure you have the report's "OnOpen" property set to
"[Event Procedure]"? Could there be a fault of some kind in your code,
that is causing it not to execute?

I'm definitiely using the Open event, and the OnOpen property is set of
[Event Procedure]. That's what's got me tearing my hair out. As far as bugs
in my code, I don't think so. I've set a breakpoint in my Open routine, so I
know if the code runs or not. If I run this line of code from the function
that runs the report, the Open event fires:

DoCmd.OpenReport <report name>, acViewPreview

OTOH, if I run this, the Open event doesn't fire:

DoCmd.OpenReport <report name>, acViewNormal

Your post inspired me to create a simple database with one report to test
this, and the Open event fired on acViewNormal. I'll be darned if I can see
anything in my code that could be causing the event to fail to fire, so I'm
going to have to do some more digging and breakpoint setting.

No wonder I've got grey hair... <vbg>

Thanks,
Mark
 
R

Rich K

Mark,
Just an idea, but might the report still be closing on the previous
interation, thus technically still open? Perhaps you need to build in a bit
of a delay so that the report actually closes all the way before you begin to
open it again.
 
A

Allen Browne

Might be worth a decompile.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Mark VII said:
Hi Dirk --
The Open event ought to fire, even when you open the report in normal
view. Are you sure it's the Open event you're using, not the Activate
event? Are you sure you have the report's "OnOpen" property set to
"[Event Procedure]"? Could there be a fault of some kind in your code,
that is causing it not to execute?

I'm definitiely using the Open event, and the OnOpen property is set of
[Event Procedure]. That's what's got me tearing my hair out. As far as
bugs
in my code, I don't think so. I've set a breakpoint in my Open routine,
so I
know if the code runs or not. If I run this line of code from the
function
that runs the report, the Open event fires:

DoCmd.OpenReport <report name>, acViewPreview

OTOH, if I run this, the Open event doesn't fire:

DoCmd.OpenReport <report name>, acViewNormal

Your post inspired me to create a simple database with one report to test
this, and the Open event fired on acViewNormal. I'll be darned if I can
see
anything in my code that could be causing the event to fail to fire, so
I'm
going to have to do some more digging and breakpoint setting.

No wonder I've got grey hair... <vbg>

Thanks,
Mark
 

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