Strange Problem With DoCmd.OutputTo When Generating a PDF File.

S

Stewart Berman

Access 2007

I have the following code:

On error goto lblError
<setupt variable>
DoCmd.OutputTo acOutputReport, vRptName, acFormatPDF, vfilename, False
msgbox "Report " & vfilename & " saved."
<other code>
lblExit:
<cleanup code>
Exit sub
lblError:
msgbox "Error: " & err.description
resume lblExit
end sub

The report that is being output has an OnOpen event handler that I wanted to
walk through. I put a breakpoint on the DoCmd.OuputTo statement and then
hit F8. The report was output without steping through the code in the
OnOpen event. I then put the following code in the OnOpen event:

Debug.Print "OnOpen"
Stop

When I again tried to step through the code "OnOpen" was printed in the
immediate window but the code did not stop.

If I open the report in print preview mode the code stops at the Stop
statement.

Finally, if an error occurs in the OnOpen code the VB engine acts as though
the code completed. It does not display an error message and the error
handler in the calling routine is not invoked.

It appears as the code that processes the DoCmd.OutputTo acOutputReport to a
a PDF file is running in Runtime mode and won't allow code to break. That
would be bad enough but it also appears to bypass error handlers. It
doesn't even display a runtime error message if there is an error in the
code -- it just clears the call stack and returns.

Is there anyway around this bug?
 

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