Description
You can use the RunCode action to call a Visual Basic Function procedure.
Setting
The RunCode action has the following argument.
Action argument | Description |
Function Name | The name of the Visual Basic Function procedure to call. Put any function arguments in parentheses. Enter the function name in the Function Name box in the Action Arguments section of the Macro window. This is a required argument. Note To use the Expression Builder to select a function for this argument, click the Build button to the right of the Function Name box. Click the desired function in the list in the Expression Builder. |
Remarks The user-defined Function procedures are stored in Microsoft Access modules.
You must include parentheses, even if the Function procedure doesn't have any arguments, as in the following example:TestFunction()
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 (=).
Microsoft Access ignores the return value of the function.
Tip 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 action to run the Function procedure.
If you use the RunCode action to call a function, Microsoft 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, Microsoft Access looks for the function first in the form's or report's class module and then in the standard modules. Microsoft Access doesn't search the class modules that appear on the Modules tab in the Database window for the function specified by the Function Name argument.
This action isn't available in Visual Basic. Run the desired Function procedure directly in Visual Basic.See Also Eval function, OpenModule action.