We help IT Professionals succeed at work.
Get Started

Handling Report with No Data

mlcktmguy
mlcktmguy asked
on
117 Views
Last Modified: 2017-11-06
I have a form in the Access 2013 program that allows the user to input selection criterion for a report.  In some cases there will be no data matching their selection criterion.

To handle that situation I have logic in the report 'NoData' event.

Private Sub Report_NoData(Cancel As Integer)
'
MsgBox "No Data Meets Selection Criterion"
Cancel = True
'
End Sub

Open in new window


If I don't cancel the report it thorws and errror in the logic referencing one of the fields on the report.

The above logic work and the report is cancelled but I now get a 'Runtime Error 2501.  The Open Report Action was cancelled' error on the statement that called the report:

DoCmd.OpenReport newReportName, acViewPreview, , , acDialog

Open in new window


I realize I can put error handling right after the 'OpenReport' command but I will have to do this everywhere I call a report in the application.

Is there a cleaner way of handling this situation?
Comment
Watch Question
Owner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010
Commented:
This problem has been solved!
Unlock 2 Answers and 15 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE