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.

Action argument



Enter the name of the temporary variable.


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 Builder 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.





Name: MyVar

Expression: InputBox("Enter a non-zero number.")



Message: ="You entered " & [TempVars]![MyVar] & "."

Beep: Yes

Type: Information


Name: MyVar

Applies To: Access 2007, Access 2010 Developer, Access 2013 Developer, Access 2007 Developer, Access 2013, Access 2016, Access 2010

Was this information helpful?

Yes No

How can we improve it?

255 characters remaining

To protect your privacy, please do not include contact information in your feedback. Review our privacy policy.

Thank you for your feedback!

Change language