logo
search
Others

How to Handle Access Error 2501 When a Report Has No Data

Steve KSteve K Oct 22, 2026 868 views

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.

How to Handle Access Error 2501 When a Report Has No Data
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 you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

In Microsoft Access, press ALT + F11 to open the Visual Basic for Applications (VBA) editor.

2
Locate the calling procedure

Find the form module or standard module containing the DoCmd.OpenReport command that triggers the error.

3
Implement the On Error GoTo statement

At the beginning of your procedure, add 'On Error GoTo ErrHandler' to direct errors to a specific label.

4
Add the error handling block

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.

Add an Error Handler to the Calling Procedure
Code Execution Flow: Ensure you place an 'Exit Sub' or 'Exit Function' immediately before your ErrHandler label so that the error code doesn't accidentally run during normal, error-free execution.
Free Microsoft Office alternative

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.

Seamless compatibility with Microsoft Excel (.xlsx, .xls, .csv) formatsLightweight software that installs quickly and runs smoothly on any deviceFamiliar, user-friendly interface allowing for immediate productivityComprehensive suite including powerful Spreadsheet, Writer, Presentation, and free built-in PDF tools
microsoft office alternative - wps office

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.