Skip to content

Latest commit

 

History

History
103 lines (82 loc) · 3.76 KB

File metadata and controls

103 lines (82 loc) · 3.76 KB
title TOCTitle ms:assetid ms:mtpsurl ms:contentKeyID ms.date mtps_version f1_keywords f1_categories ms.localizationpriority
SetTempVar macro action
SetTempVar macro action
9c3b7bee-02c5-efbf-1276-4c4a1f7802d9
48546593
09/18/2015
v=office.15
vbaac10.chm150219
Office.Version=v15
medium

SetTempVar macro action

Applies to: Access 2013, Office 2013

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 buildbut_ZA06047218 to use the Expression Builder to set this argument.

Remarks

  • 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:

    =[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: MyVarExpression: InputBox("Enter a non-zero number.")

[TempVars]![MyVar]<>0

MessageBox

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

RemoveTempVar

Name: MyVar