Report Code isn't Running

J

JimP

I have a report with code in the "On Format" event for a group header
section. The code formats the section, makes certain controls visible, sets
labels etc.

The code is processed when I run
DoCmd.OpenReport strReportName, acViewPreview

The code is NOT processed when I run
DoCmd.OpenReport strReportName, acViewNormal

I tried a compact & repair on the mdb, a "\decompile" and compile on the
mdb, as well as importing all of the report objects into a new report - to
no avail.

...any suggestions as to the cause or a solution?
 
A

Allen Browne

What version of Access is this?

If A2007, you may be opening the report in one of the new views. The code
should run in Print Preview, but A2007 will not run it in Report view or in
Layout view. (Also note that A2007 doesn't run any code unless you trust the
folder where the database resides.)

If it's an earlier version, it's something else. Perhaps you want to add the
line:
Debug.Print "Group header Format ran at " & Now()
to the top of the event procedure. After viewing the report, open the
Immediate Window (Ctrl+G) to see if it even started the event.
 
J

JimP

This is MS-Access 2003.

This is a multi-user environment where some users may be on MS-Access 2007.
The accdb has all macros enabled. I think this should resolve any issues
about code running (although I am not sure).

I'll try your suggestion, but I'm pretty confident the code is not running -
can't figure this one out yet.
 
J

JimP

Upon examining the code further, the code that is not running is in the "On
Activate" event for the report.

The codes runs in "Preview", but not "Print"
 
A

Allen Browne

JimP said:
Upon examining the code further, the code that is not running is in the
"On Activate" event for the report.

The codes runs in "Preview", but not "Print"

That's correct behavior, exactly as MS intended.

The Activate event occurs when the window that displays the report on screen
takes focus. If you print without preview, there is no window on screen, so
no Activate event is fired.

By design.
 
J

JimP

Thankyou, I moved the code to the "On Format" event of the Report Header
section and it's fine.
 

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