How to Fix Microsoft Access Return Without GoSub Error in Reports
Question details
The user is encountering a "Return without GoSub" error when attempting to open a report in Microsoft Access.

- 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.
Open your Microsoft Access database in Design View and ensure the VBA Editor is accessible by pressing Alt + F11 before modifying event procedures.
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.
Right-click the problematic report in the navigation pane and select 'Design View'.
Press F4 to open the Property Sheet, navigate to the 'Event' tab, and locate the 'On Open' property.
Click the ellipsis (...) next to the 'On Open' property to open the associated VBA module or macro.
Scroll to the very top of the module and type 'Option Explicit' to force the explicit declaration of all variables.
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.

Resolve Missing Library References
Missing object library references can cause Access to misinterpret VBA statements, leading to inaccurate runtime errors.
Isolate the Error by Disabling Macros
Temporarily disable the associated macro or event code to confirm if the report itself is corrupted or if the issue is strictly code-related.
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.

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.




