no data on reports

J

jnewl

have a form where the user thru option buttons can select a specific report.
based on those options, certain queries are activated. have used the nodata
option on reports to generate a msgbox and cancel = true. the problem is that
after the message box displays, get a run time error of 2501 - open report
error. have searched the responses that have been posted on this site. tried
using those suggestions, but still have the same problem.

here is the code that selects the reports

If Forms![select ancillary group]![report category] = 4 Then
DoCmd.OpenQuery "qry select service request not created for reports"
If Forms![select ancillary group]![group var] = "facility" Then
stDocName = "facility service request"
DoCmd.OpenReport stDocName, acPreview
Else
stDocName = "ancillary and physician service request"
DoCmd.OpenReport stDocName, acPreview
End If


here is the nodata code on the report
Private Sub Report_NoData(Cancel As Integer)



MsgBox "NO DATA TO REPORT", , "ancillary and physician report"
Cancel = True

End Sub

once the cancel occurs, tries to open the report

what code can i insert to prevent this? thanks much for your help
 
J

jnewl

worked fine.... thanks much

Allen Browne said:
Copy the OpenTheReport() function from this page:
http://allenbrowne.com/AppPrintMgtCode.html#OpenTheReport

Paste it into a standard module.

Then use OpenTheReport() instead of OpenReport.
It uses error handling to suppress error 2501.
Test the return value if you want to know if the report opened.

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

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

jnewl said:
have a form where the user thru option buttons can select a specific
report.
based on those options, certain queries are activated. have used the
nodata
option on reports to generate a msgbox and cancel = true. the problem is
that
after the message box displays, get a run time error of 2501 - open report
error. have searched the responses that have been posted on this site.
tried
using those suggestions, but still have the same problem.

here is the code that selects the reports

If Forms![select ancillary group]![report category] = 4 Then
DoCmd.OpenQuery "qry select service request not created for reports"
If Forms![select ancillary group]![group var] = "facility" Then
stDocName = "facility service request"
DoCmd.OpenReport stDocName, acPreview
Else
stDocName = "ancillary and physician service request"
DoCmd.OpenReport stDocName, acPreview
End If


here is the nodata code on the report
Private Sub Report_NoData(Cancel As Integer)



MsgBox "NO DATA TO REPORT", , "ancillary and physician report"
Cancel = True

End Sub

once the cancel occurs, tries to open the report

what code can i insert to prevent this? thanks much for your help
 

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