I need some help with global variables scope, please.

BukHix

Registered User.
Local time
Today, 14:11
Joined
Feb 21, 2002
Messages
379
I am working on a way to hold a variable throughout the life of an application. I created a module like this:

Code:
Option Compare Database
Option Explicit

Public strUname As String
Public strPword As String
Public intAccess As Integer

The idea is to use a login form with a user name and password to get the access level of the person using the database. I am using this code temporarily to make sure I am getting the right results.

Code:
If Not IsNull(DLookup("Username", "tblSupers", "([UserName]= '" _
     & Me!txtUname & "') and ([Password]= '" & Me!txtPword & "')")) Then
     MsgBox ("Found a match")

Else

     MsgBox ("No Match was found")
     Exit Sub

End If
    
strUname = Me.txtUname
strPword = Me.txtPword
intAccess = DLookup("LocCode", "tblSupers", "[UserName]= '" & strUname & "'")
    
MsgBox (strUname & strPword & intAccess)

With this code I know that I am getting the right criteria back.

I understand that the variables are held in the memory of each computer accessing it and will be killed when the app on each computer when the app is closed. Is there a problem with having multiple computers connected to the database, all using the same public variables at the same time? I mean they will be the same public calls but using unique variables.
 
Variables are "Instance" specific.
 
Buk
I think Travis is right. Each time a Dimension request is made, a new memory address is created on the host machine to hold the variable value. Therefore each machine's value for a global variable is unique.
I have something like what you are doing running here, with no problems...
Chris
 

Users who are viewing this thread

Back
Top Bottom