Fix an Access RunCode Macro That Cannot Find a VBA Function
Question details
Make a VBA function available to an Access macro that calls it with RunCode.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- An Access macro uses the RunCode action to call a VBA function.
- Observed behavior
- The macro reports that it cannot find the function name.
Identify the function name used in the macro and locate its code in the VBA editor. If Access displays a security warning, enable content only if you trust the database.
Make the VBA function available to the RunCode macro
Use this approach when RunCode cannot find a function because of its location, declaration, call syntax, or a naming conflict.
In Access, press Alt+F11 and find the function in the Project Explorer. If it is in a form or report module, move its code to a standard module using Insert > Module.
In the standard module, declare the procedure as a Public Function rather than a Sub. For example, use Public Function Master() and end it with End Function; assign a return value if the function needs to provide one.
In the Navigation Pane and Project Explorer, check for names that conflict with the function, including the module name and names of tables, queries, or controls. Rename conflicting objects or the function, then update any references.
In the VBA editor, select Debug > Compile and correct any reported errors. Save the module after compilation succeeds.
Open the macro in Design View and enter Master() in the RunCode action's Function Name field, replacing Master with your actual function name. Save and run the macro.

Work with Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with documents, spreadsheets, and presentations. Open supported Office files to make the transition easier. WPS Office does not run Access databases or fix Access RunCode macros.

Frequently Asked Questions
Can RunCode call a function in a form module?
For a reliable RunCode call, place the Public Function in a standard module. In the VBA editor, select Insert > Module and move the function there.
What should I enter in the RunCode Function Name field?
Enter the function name with parentheses, such as Master(). If the function requires arguments, supply them inside the parentheses.
Why does the function still fail after I move it?
In the VBA editor, select Debug > Compile and fix any errors. Also check that the function is public and that its name does not conflict with its module or another database object.
Can RunCode call a VBA Sub procedure?
RunCode calls a Function, not a Sub. Change the procedure to a Public Function in a standard module and update the macro's Function Name field.




