SetTempVar Macro Action
You can use the SetTempVar action to create a temporary variable and set it to a specific value. The variable can then be used as a condition or argument in subsequent actions, or you can use the variable in another macro, in an event procedure, or on a form or report.
The SetTempVar action has the following arguments.
|Name||Enter the name of the temporary variable.|
|Expression||Enter an expression that will be used to set the value for this temporary variable. Do not precede the expression with the equal (=) sign. You can click the Build button to use the Expression Builder to set this argument.|
- You can have up to 255 temporary variables defined at one time. If you do not remove a temporary variable, it will remain in memory until you close the database. It is a good practice to remove temporary variables when you are finished using them. To remove a single temporary variable, use the RemoveTempVar action and set its argument to the name of the temporary variable that you want to remove. If you have more than one temporary variable and you want to remove them all at once, use the RemoveAllTempVars action.
- Temporary variables are global. Once a temporary variable has been created, you can refer to it in an event procedure, a Visual Basic for Applications (VBA) module, a query, or an expression. For example, if you created a temporary variable named MyVar, you could use the variable as the control source for a text box by using the following syntax:
Note In macros, queries and event procedures, you do not need to precede the expression with an equal sign.
You can also refer to temporary variables in any add-ins or referenced databases.
- To run the SetTempVar action in a VBA module, use the Add method of the TempVars object.
The following macro demonstrates how to create a temporary variable by using the SetTempVar action, then using the temporary variable in a condition and a message box, and then removing the temporary variable.
Expression: InputBox("Enter a non-zero number.")
Message: ="You entered " & [TempVars]![MyVar] & "."