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.

Setting

The SetTempVar action has the following arguments.

Action argument Description
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 Button image to use the Expression Builder to set this argument.

Remarks

=[TempVars]![MyVar]

 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.

Example

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.

Condition Action Arguments
SetTempVar

Name: MyVar

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

[TempVars]![MyVar]<>0 MsgBox

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

Beep: Yes

Type: Information

RemoveTempVar Name: MyVar
 
 
Applies to:
Access 2007