How to Handle Access Error 2501 When a Report Has No Data
Question details
The user needs a method to prevent or handle Runtime Error 2501 in Microsoft Access when a report is canceled from its NoData event.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Executing a DoCmd.OpenReport VBA command to preview a report that turns out to have no underlying records, triggering the NoData event cancellation.
- Observed behavior
- Instead of gracefully cancelling the report, Access throws runtime error 2501 ('The OpenReport action was canceled') in the calling procedure and displays an unhandled error pop-up.
Before modifying your VBA code, it is highly recommended to create a backup copy of your Access database (.accdb or .mdb) to prevent accidental data corruption or code loss.
Add an Error Handler to the Calling Procedure
Since the 2501 error is raised in the procedure that executes DoCmd.OpenReport, catching the error there prevents the unhandled exception pop-up.
When the NoData event of an Access report cancels the report generation, the control returns to the code block that originally requested the report to open. By trapping the specific error number (2501), your code can silently ignore the expected cancellation while continuing to alert you of unexpected errors.
In Microsoft Access, press ALT + F11 to open the Visual Basic for Applications (VBA) editor.
Find the form module or standard module containing the DoCmd.OpenReport command that triggers the error.
At the beginning of your procedure, add 'On Error GoTo ErrHandler' to direct errors to a specific label.
At the bottom of the procedure, add the 'ErrHandler:' label. Use a 'Select Case Err.Number' block to trap 'Case 2501' without triggering a message box, while letting 'Case Else' display standard error descriptions using MsgBox Err.Description.

Configure the Report's NoData Event Properly
Ensure that your report is properly configured to cancel itself and inform the user before passing the cancellation back to the calling procedure.
Explore WPS Office for Powerful Data Management
While Microsoft Access is built for complex relational databases, many users find WPS Spreadsheet an incredibly capable, lightweight alternative for managing datasets, creating reports, and analyzing data without requiring complex VBA coding. It is fully compatible with Excel formats and free to use.

Frequently Asked Questions
What does Access Error 2501 mean?
Error 2501 is a runtime error indicating that a macro or VBA action (such as opening a report, form, or executing a query) was canceled before it could complete. This most commonly occurs when a report cancels itself via the On No Data event.
Why doesn't the error handler inside the report catch error 2501?
The 2501 error is raised in the calling procedure (the code that initiated the DoCmd.OpenReport command), not inside the report's internal event module. Therefore, the error must be handled where the OpenReport command was issued.
Can I suppress the default Access error message without using VBA?
Generally, no. If a report is opened via VBA and gets canceled, Access requires a VBA error handler in that specific calling procedure to gracefully catch and ignore error 2501. Using macros with the 'OnError' action can sometimes handle this, but VBA offers the most precise control.




