Err running OpenReport in module function

J

JerryC

I am using Autoexec macro to RunCode that will
automatically print a report when application starts.

This line is in a module.
DoCmd.OpenReport "PMR1", acViewNormal, "PMQAutoPrintDues"

If there is data for the report it prints out OK.

If query for report returns nothing then I use the On No
Data event on the report to show a message.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to print", vbOKOnly, "No
report"
Cancel = True
DoCmd.Close acReport, "PMR1"
End Sub

When there is no data for the report I get the
message "There are no records to print" then an error
message saying the Action Failed.
How can I stop the Action Failed message or trap it???

Thanks in advance for your help
 
W

Wayne Morgan

The cancel error gets returned to the calling code. A macro doesn't have a
way to handle this. It would be better to put the call in the form you open
initially. You could trap this error in the VBA code behind the form.

Setting Warnings to False in the macro before making the call may help, but
I don't know. I don't normally use macros.
 

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