Others

Fix VBA Function Not Running with Access RunCode Macro Action

Maira MehtabMaira Mehtab Nov 4, 2026 868 views

Question details

The user needs to make a public VBA function run successfully using the RunCode macro action in MS Access.

How to Fix VBA Function Not Running in Access RunCode Macro Action
Product
Microsoft Access 2019
Device & OS
not provided
Scenario
Executing a public VBA function from an Access macro using the RunCode action.
Observed behavior
The function does not run, breakpoints or Debug.Print statements are never reached, and no error message is displayed.
Before you start

Verify that your VBA code compiles without errors by opening the VBA Editor and clicking Debug > Compile Database before attempting to run the macro.

Solution 1Recommended

Verify Function and Module Requirements

Ensure the function is set up correctly in a standard module so that the RunCode macro can locate and execute it.

Microsoft Access imposes strict requirements on how functions must be structured and located to be executed by the RunCode macro action. If these rules are not followed, the action will fail silently.

1
Set the function to Public

Open the VBA Editor (Alt + F11) and ensure the function is declared exactly as a 'Public Function' rather than a Private Function or Sub.

2
Place inside a Standard Module

Check the module containing the function in the Project Explorer. It must be stored in a standard module, not behind a class module, Form, or Report.

3
Rename overlapping module names

Ensure the module name is entirely different from the function name. For example, if your function is named GetEnviron, the module itself cannot be named GetEnviron.

4
Format the RunCode argument

In the RunCode macro argument box, enter the function name exactly as it appears with parentheses (e.g., GetEnviron()), omitting any leading equals sign.

Verify Function and Module Requirements
Testing Execution: Place a breakpoint on the first line of your function by pressing F9 in the VBA Editor. When you run the macro, execution will pause there if the setup is successful.
Free Microsoft Office alternative

Discover WPS Office for Your Daily Document Needs

While Microsoft Access handles complex database management, WPS Office provides a free, lightweight, and highly compatible alternative for your Word, Excel, and PowerPoint files. Enjoy a familiar interface and seamless transition for your spreadsheets, presentations, and document editing.

  1. 1. Download the software: Visit the official WPS website and download the free installer for your operating system.
  2. 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to complete the setup.
  3. 3. Open and Edit: Double-click any existing Microsoft Office document to instantly open and edit it in WPS Office.
Highly compatible with Microsoft Office formats including DOCX, XLSX, and PPTXFree and lightweight alternative for daily document processingFamiliar user interface requires almost zero learning curveBuilt-in PDF editing and conversion tools
microsoft office alternative - wps office

Frequently Asked Questions

Why does the RunCode action require a Function instead of a Sub?

In Microsoft Access, the RunCode macro action is specifically designed to evaluate and execute User-Defined Functions (UDFs) that optionally return a value. It cannot call a Sub procedure directly. If you need to run a Sub, you must wrap it inside a Public Function.

Can I pass arguments to the function within the RunCode action?

Yes, you can pass arguments by including them inside the parentheses after the function name in the RunCode argument box. String arguments should be enclosed in quotes.

How can I verify if my database VBA project compiles successfully?

Open the VBA Editor by pressing Alt + F11, then click on 'Debug' in the top menu and select 'Compile Database'. If there are errors, the editor will highlight them; if nothing happens, the code compiles successfully.