UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Edit Discussion
> TempVars    

Contents

TempVars

Tempvars was introduced in Access 2007 and has proven very handy. TempVars is really more of an object with a collection, is used much like a function, and behaves very much like a global variable.

• Tempvars can be used in queries without a supporting function
• Tempvars can be created in any module type
• Tempvars maintain their set value even under the duress of a code error
• Tempvars are global by nature

The Syntax

To add (create) or modify a TempVars variable:

TempVars.Add "Name", Value

Here are some examples:

CODE
TempVars.Add "curTotalTrans", 356.60

CODE
TempVars.Add "lngCustID", 4455

CODE
TempVars.Add "bolIsActive", True

CODE
TempVars.Add myFieldVar, "New User Name"

(where "myFieldVar" might be a variable you've used to store the name of a field or control for the user name and "New User Name" is the value of that user name field/control)

Usage

Once the values are assigned you can use them in your queries and code with various syntaxing:

CODE
TempVars!curTotalTrans

CODE
TempVars.Item("curTotalTrans")

CODE
TempVars.Item(myFieldVar)

CODE
TempVars.Item(0)

All four methods above will return "356.60" (if you assigned the number to myFieldVar)

Removal

Use the "Remove" method to remove a single variable or use '.RemoveAll' to clear all of them.

CODE
TempVars.Remove "curTotalTrans"

CODE
TempVars.Remove myFieldVar

CODE
TempVars.RemoveAll




Creative Commons License
TempVars by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Thank you for your support!
This page has been accessed 100,304 times.  This page was last modified 16:36, 18 February 2014 by Mark Davis. Contributions by DLavell, Pere_de_chipstick and George Hepworth  Disclaimers