Fix VBA Function Not Running with Access RunCode Macro Action
Question details
The user needs to make a public VBA function run successfully using the RunCode macro action in MS Access.

- 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.
Verify that your VBA code compiles without errors by opening the VBA Editor and clicking Debug > Compile Database before attempting to run the macro.
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.
Open the VBA Editor (Alt + F11) and ensure the function is declared exactly as a 'Public Function' rather than a Private Function or Sub.
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.
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.
In the RunCode macro argument box, enter the function name exactly as it appears with parentheses (e.g., GetEnviron()), omitting any leading equals sign.

Add Database to Trusted Locations
MS Access will silently block VBA code and macros if the database is not running from a Trusted Location.
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. Download the software: Visit the official WPS website and download the free installer for your operating system.
- 2. Install WPS Office: Run the downloaded installer and follow the simple on-screen instructions to complete the setup.
- 3. Open and Edit: Double-click any existing Microsoft Office document to instantly open and edit it in 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.




