Solved: Declaring Global Variables in Access 2007

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

SimonB

Thread Starter
Joined
Sep 21, 2004
Messages
24
Access 2007 is supposed to handle global variables much better than previous versions, but I can't seem to find any instruction on how and where to declare them. I am working in multiple form modules, and I want a variable that will stay active, with a set value that can be changed from time to time as needed, throughout the Access session, from one form to another. Can someone help me with this?
Thanks, SimonB
 

OBP

Joined
Mar 8, 2005
Messages
19,895
Simon, isn't it the same as previous versions, i.i. in a module?
 
Joined
Sep 4, 2003
Messages
4,912
Declare the variable in a stand alone module and use the following syntax.

Code:
Public myGlobalVar As String
Regards,
Rollin
 

SimonB

Thread Starter
Joined
Sep 21, 2004
Messages
24
In my digging over the last hour or so there seems to be a new collection (my symantics may be wrong here) of "Temporary Variables" that remain in memory until you close the database. It's a collection of variables that can be used application-wide and survive code resets, unlike previous Access versions. Example: In AutoExec macro, SetTempVar named LicensedTo to "Acme Corporation", and add this text box to each report header: =[TempVars]![LicensedTo]. I've been able to declare the TempVar, but can't find how to change its value.

Here's what I have found. It's interesting.
http://blogs.msdn.com/thirdoffive/archive/2006/04/13/570539.aspx
http://www.allenbrowne.com/Access2007.html (search for "TempVar")
 

SimonB

Thread Starter
Joined
Sep 21, 2004
Messages
24
OK, looks like I may have got it. This is the syntax:
This declares the global(TempValue) variable:
TempVars("tempvariablename").Value = initialvalue (the ".Value" is optional)
(you have to give it a value, and do not declare a type)
This is the syntax for changing that value anywhere you need to:
[TempVar]![tempvariablename].Value = new-value
(it seems you need to specify the parameter ".Value" here)
And this is how to use the TempVariable elsewhere:
variablename = [TempVar]![tempvariablename].Value
Thanks, anyway, gang.
Best, SimonB
 

SimonB

Thread Starter
Joined
Sep 21, 2004
Messages
24
I thought I had it, but it seems now I don't. Here's what I am doing:
I declare the TempVars this way:
TempVars("LoginAttemptCounter").Value = Val("0")
TempVars("MaxAllowedLoginAttempts").Value = Val("3")
Then I loop through a process of validating login credentials, with this check in it:
If [TempVar]![LoginAttemptCounter] < [TempVar]![MaxAllowedLoginAttempts] Then...
The compiler doesn'y like this statement. My syntax is bad, somehow. Does anyone see the problem?
SimonB
 

OBP

Joined
Mar 8, 2005
Messages
19,895
Simon, wouldn't it be better to assign the TempVar to a declared Variable in you current procedure and use that for comparisons.
 

SimonB

Thread Starter
Joined
Sep 21, 2004
Messages
24
OBP,
Someone sent me the solution. Instead of this to refer to the TempVar:
[TempVar]![tempvariablename].Value
...use this:
TempVars("tempvariablename").Value
It works.
Thanks for your help.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top