You run Visual Basic code in Microsoft Access by running a Sub procedure or Function procedure. Procedures contain a series of statements and methods that perform an operation or calculate a value.
Procedures are stored in units called modules. However, you don't run a module; rather, you call the procedures from expressions, other procedures, or macros. Event procedures in form or report modules also run in response to user actions.
Here are the ways to run Visual Basic code in Microsoft Access:
For example, you can add code to the Click event procedure of a command button that opens a form when a user clicks the button. For more information on creating an event procedure, click .
For example, you can use a function in an expression that defines a calculated field in a form, report, or query. You can use expressions as property settings in queries and filters, in macros and actions, in Visual Basic statements and methods, or in SQL statements. For more information on creating a custom function, click .
If you have certain code you run frequently, you can put it in a Sub procedure. Rather than repeating the Visual Basic code that performs the operation in each procedure, you write it once in the common procedure and then call the common procedure each time you want to perform the operation. For more information on creating a Sub procedure, click .
In the Code window, place the cursor in the procedure that you want to run. Then click Run Sub/UserForm on the Run menu.
You can use the RunCode action to run a built-in Visual Basic function or a function you've created. To run a Sub procedure or an event procedure, create a function that calls the Sub procedure or event procedure, and then use the RunCode action to run the function. For more information on the RunCode action, click .