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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Constant global variable

Status
Not open for further replies.

eloise

Programmer
Jan 31, 2002
20
0
0
US
Hi

I'm new to access and sql server and my question is this:

I have a form that acts as a login dialog box. When the user enters the correct details a user id is returned from the database. This helps me identify the users access to other forms in the application. I want to store the returned user id in a global constant variable, or a global variable, so that i can refer to it every time I enter a new form.

So far what I have done is store the returned value in a field on the login dialog box. Then I assign the field to a global variable. Access XP doesn't like this. Is there anyway round this problem. Please help as I cannot move forward with developing my app.

the code so far to store the value to a global variable

module mdGlobalVariables

Public Const conUserid As Integer = forms!formLoginScreen!txtUserID

Error:

Constant expression required.


Thanks in Advance


 
Hi,

If the data is stored in a field on the login form, you could refer to it instead of creating a global variable. You already have the syntax:

forms!formLoginScreen!txtUserID

The form needs to remain open, but you could hide it with Form.Visible = False

Just another option that you might consider. dz
 
eloise - I have done this task previously and used the following:

Create a new Module and save it as something like "GlobalVar"

In this module type:

Code:
Public strUserName as String

In your login form, you will more than likely have a control for the username? Well, when you click your 'OK' button to validate the username / password as the following code:

Code:
GlobalVar.strUsername = ControlName

This will store the username as a global variable. To call on this for other controls, simply use on the form the control relates to:

Code:
ControlName = GlobalVar.strUsername

HTH's
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top