Others

Fix an Access RunCode Macro That Cannot Find a VBA Function

Aamir Naveed AkramAamir Naveed Akram Nov 20, 2026 868 views

Question details

Make a VBA function available to an Access macro that calls it with RunCode.

Fix an Access RunCode Macro That Cannot Find a VBA Function
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

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.

2
Declare a public function

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.

3
Check object names

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.

4
Compile the project

In the VBA editor, select Debug > Compile and correct any reported errors. Save the module after compilation succeeds.

5
Update and test the macro

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.

Make the VBA function available to the RunCode macro
Functions with arguments: If the function requires arguments, include appropriate values inside the parentheses in the RunCode Function Name field.
Free Microsoft Office alternative

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.

Create and edit spreadsheets for suitable data tasks.Open and edit Microsoft Office formats including DOCX, XLSX, and PPTX.Navigate a familiar interface when moving from Office applications.Use a free, lightweight suite for everyday document work.
microsoft office alternative - wps office

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.