Need Help creating Global Variables in a Module

adammorrisey

New member
Local time
Today, 05:22
Joined
Nov 20, 2012
Messages
8
Let me start off by saying that my coding experience if fairly limited, I have used Access for about 4 months now for a course.

Now to my problem....

I want to create a global variable "EmployeeCode" so that once a user signs in using their password on a form, all the additional forms would by associated with the particular employee signed in.

Any help would be greatly appreciated:)
 
If you are using A2007 or A2010 use a TempVar. It is more stable than a global variable. When I use Globals in an application, I create a separate code module and define them all there. That way I don't need to riffle through multiple modules when I'm looking for one. Globals defined in the class modules of forms and reports are only available while that form is open. That may be why you are having trouble. You may have defined the Global in the login form and then it went out of scope when the form closed.

I actually don't close my login form, I just hide it. That way the form is always open and I can refer to it anywhere so it serves the same function as a global. The advantage is that during testing, you can leave the login form visible so you can actually see the values of your "globals" and modify them to facilitate testing.
 
Like Pat, when I use them I put Global variables in their own module too.

Similarly I prefer to keep such values as a variable in a Class. However that class can be something other than a Form. Like a hidden form it is necessary to maintain an instance of the class while the variable is required.

One construction I particularly liked was a class that read multiple details about the logged in user from an LDAP server on our domain.

Pat's reference to stability is because all variables are lost when the project is reset. With expereince one learns how to avoid a reset after a Break so it becomes less of a problem. Alternatively the class holding the variable can be reinstantiated as required.

BTW I have always found the name TempVar rather incongruous because, short of storing a value in a file or table, of all the variables one can use they are the most non-temporary.
 

Users who are viewing this thread

Back
Top Bottom