logo
search
VBA & Macro Problems

How to Fix Microsoft Access Return Without GoSub Error in Reports

Nimra MalikNimra Malik Sep 30, 2026 869 views

Question details

The user is encountering a "Return without GoSub" error when attempting to open a report in Microsoft Access.

How to Fix Microsoft Access Return Without GoSub Error When Opening Reports
Product
Microsoft Access
Device & OS
not provided
Scenario
Opening a database report that triggers an On Open event containing macros or VBA event procedures.
Observed behavior
Access displays a "Return without GoSub" error message and fails to execute the report properly, indicating a faulty macro or an unmatched Return statement in the VBA code.
Before you start

Open your Microsoft Access database in Design View and ensure the VBA Editor is accessible by pressing Alt + F11 before modifying event procedures.

Solution 1Recommended

Check the On Open Property and Compile VBA Code

Identify the macro or event procedure triggering the error and compile your VBA code to locate unmatched Return statements.

The error most commonly occurs when the VBA engine encounters a Return statement but has not previously executed a corresponding GoSub statement. Compiling the project helps pinpoint the exact line of code causing the problem.

1
Open the report in Design View

Right-click the problematic report in the navigation pane and select 'Design View'.

2
Access the Property Sheet

Press F4 to open the Property Sheet, navigate to the 'Event' tab, and locate the 'On Open' property.

3
Open the VBA Editor

Click the ellipsis (...) next to the 'On Open' property to open the associated VBA module or macro.

4
Add Option Explicit

Scroll to the very top of the module and type 'Option Explicit' to force the explicit declaration of all variables.

5
Compile the Database

In the VBA Editor's top menu, click 'Debug' and select 'Compile [Your Database Name]'. Access will highlight any syntax errors, including unmatched Return statements, for you to correct.

Check the On Open Property and Compile VBA Code
Compilation Successful: If the code compiles without highlighting errors, the issue may reside in a corrupted macro rather than the VBA script itself.
Free Microsoft Office alternative

Looking for a Lightweight Office Suite Alternative?

If you frequently encounter complex macro errors in Microsoft Office, consider WPS Office as a lightweight, highly compatible alternative for your daily document, spreadsheet, and presentation needs.

Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Free and lightweight suite designed for everyday office productivity.Familiar user interface for seamless migration and minimal learning curve.Includes a powerful built-in PDF editor and converter.
microsoft office alternative - wps office

Frequently Asked Questions

What causes the "Return without GoSub" error in Access?

This error typically occurs when a VBA procedure executes a `Return` statement but has not previously executed a corresponding `GoSub` statement. It can also be triggered by corruption in a macro linked to the report's On Open event.

What does 'Option Explicit' do in Access VBA?

Adding 'Option Explicit' at the top of a VBA module forces the explicit declaration of all variables. This helps developers quickly identify undeclared or misspelled variables that might otherwise trigger unexpected runtime errors during compilation.

How do I fix compilation errors in Microsoft Access?

Open the VBA Editor by pressing Alt + F11, click 'Debug' in the top menu, and select 'Compile Database'. Access will stop and highlight the first error it finds. You must fix this error and repeat the process until the 'Compile Database' option is grayed out, indicating all syntax errors are resolved.