no data on reports

  • Thread starter Thread starter jnewl
  • Start date Start date
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
 
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
 
Back
Top