Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring a global variable 1

Status
Not open for further replies.

eloise

Programmer
Jan 31, 2002
20
0
0
US
Help

How do i declare a global variable that will be used throughout my application. I need this variable to store my user id, which will determine what the user can do on various screens. Thank you in advance

Eloise

 
In the top of a module

Option Compare Database 'Use database order for string
Global UserID ' Usernumber
 
I have tried this but i receive an error saying
"Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules"

Is there anything that I have to set or do first of all. Thanks in advance
 
eloise,

You can't set Global variables in an object based module (ie. the code for a form).
You will have to create a new module from the main module section and enter the code herman suggested there.

starsky51
 
Is the "New" module just created in the module area? How does Access process this module first to know that the "global variable" defined is used in another Form?
 
Kumo,
Yes just create a new module and give it a meaningful name.

I'm not entirely sure of the ins and outs of how Access works with it's modules but I assume it updates a list, in memory, of the Public/Global Variables and Functions that are in each module, before it runs any form code.

Hope that makes sense!

starsky51
 
Why not declare the variable in GLOBAL (Dim statement or PUBLIC) and set the values in the 'oncurrent' of your first or main form. I ususally just points to other forms, doing nothing else useful.

Rollie E
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top