RunCode Macro Action

You can use the RunCode macro action in Access desktop databases to call a Visual Basic for Applications (VBA) Function procedure.


The RunCode macro action has the following argument.

Action argument


Function Name

The name of the VBA Function procedure to call. Enclose any function arguments in parentheses. Enter the function name in the Function Name box in the macro design window. This is a required argument.

Note: In an Access desktop database (.mdb or .accdb), click the Build button to use the Expression Builder to select a function for this argument. Click the desired function in the list in the Expression Builder.


The user-defined Function procedures are stored in Microsoft Office Access 2007 modules.

You must include parentheses, even if the Function procedure doesn't have any arguments, as in the following example:


Unlike user-defined function names used for event property settings, the function name in the Function Name argument doesn't begin with an equal sign (=).

Access ignores the return value of the function.

Note: You can't call a Function procedure from a macro if the function name is the same as the module name.


To run a Sub procedure or event procedure written in Visual Basic, create a Function procedure that calls the Sub procedure or event procedure. Then use the RunCode macro action to run the Function procedure.

If you use the RunCode macro action to call a function, Access looks for the function with the name specified by the Function Name argument in the standard modules for the database. However, when this action runs in response to clicking a menu command on a form or report or in response to an event on a form or report, Access first looks for the function in the form's or report's class module and then in the standard modules. Access doesn't search the class modules that appear in the Modules area of the Navigation Pane for the function specified by the Function Name argument.

This action isn't available in a VBA module. Instead, run the desired Function procedure directly in VBA.

Connect with an expert
Contact us
Expand your skills
Explore training

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.