TempVars?

mkaeser

Registered User.
Local time
Yesterday, 22:37
Joined
Apr 14, 2014
Messages
74
Hello all,

So I have read through threads, such as this
http://www.access-programmers.co.uk/forums/showthread.php?t=270155&highlight=tempvars
In regards to tempvars and what (if any) benefit they might have. The database I am working through uses these everywhere, in macros, in VBA, in queries, on forms, they are all over the place. But, I don't see why they are needed anywhere other than in macros. For example, say I have form 1 open and I want more details about the customer, so I click a button with VBA behind it to open form 2 to show that record:
docmd.openform "Form2"

Now I will either open the form using this code:
docmd.openform "Form2", acNormal,,"[ID]=" & Me.ID

OR, if I am using a variable that needs to hold its value throughout the DB, I have a table that houses these variables and code that will set or get the variable value:
docmd.openform "Form2", acNormal,,"[ID]=" & GetVarValue(NewClientID)

The database I am working with have this type of code:
TempVars!MyTempProjectID = [ID].Value
MyProjectID = TempVars!MyTempProjectID
docmd.openform "Form2", acNormal,,"[ID]=" & MyProjectID

This seems like a lot of unnecessary steps to me, but perhaps there is something I am overlooking? I feel it would be better to keep any variables that are meant to be global in a table so you can easily find the value source and description of what the variable is used for, but maybe there is a benefit to using the tempvars like this in VBA code?
 
In the context that you are using it there may not be an advantage. But I some cases it could be usefull to have it available at the db level. Like in case after you went to form 2 there may be an option to pull a third form or perform some operation that used the record id. In your case it could be that they used it in order to keep their variable usage consistent through out the application to make it easier to read and trouble shoot the code... Just my guess...
 
Hello all,

So I have read through threads, such as this
http://www.access-programmers.co.uk/forums/showthread.php?t=270155&highlight=tempvars
In regards to tempvars and what (if any) benefit they might have. The database I am working through uses these everywhere, in macros, in VBA, in queries, on forms, they are all over the place. But, I don't see why they are needed anywhere other than in macros. For example, say I have form 1 open and I want more details about the customer, so I click a button with VBA behind it to open form 2 to show that record:
docmd.openform "Form2"

Now I will either open the form using this code:
docmd.openform "Form2", acNormal,,"[ID]=" & Me.ID

OR, if I am using a variable that needs to hold its value throughout the DB, I have a table that houses these variables and code that will set or get the variable value:
docmd.openform "Form2", acNormal,,"[ID]=" & GetVarValue(NewClientID)

The database I am working with have this type of code:
TempVars!MyTempProjectID = [ID].Value
MyProjectID = TempVars!MyTempProjectID
docmd.openform "Form2", acNormal,,"[ID]=" & MyProjectID

This seems like a lot of unnecessary steps to me, but perhaps there is something I am overlooking? I feel it would be better to keep any variables that are meant to be global in a table so you can easily find the value source and description of what the variable is used for, but maybe there is a benefit to using the tempvars like this in VBA code?

I have been a great fan of globals but recently I have switched to TempVars for variables that hold session values. All things being roughly equal, using TempVars saves me code to test and reset the session globals after crashes. Most useful !

Best,
Jiri
 
A thing that is more available and accessible is more likely to be corrupted, hijacked, misused or polluted, and this is true of variables too. In principle it is always best to minimize the scope of variables.
 

Users who are viewing this thread

Back
Top Bottom