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!

User Login

Status
Not open for further replies.

Vcscwi

Programmer
Jan 15, 2004
57
0
0
US
Have Access database where I would like the user to login. Have the screen for the user to login.

What I need help on is setting the "global" variable so throught the project I know who is logged in. I created a Modudle called GlobalVar and all that is in it is:

Global iUser as Integer

I call it in the OnOpen of my Login form:
DoCmd.OpenModule "GlobalVar"

But when I reference the iUser variable, it says "Ambiguous name dected: iUser"

What am I missing or is there a better way to achieve the samething?

Thanks
 
I use a public variable set in a module called pubVariables.
i.e.

Public UserID as string

then when the user opens the project i capture their user name from windows:

UserID = Environ("UserName")

then I use UserID throughout the project to log user activity.

i.e. if John Smith's windows user name is jsmith, then
UserID = Environ("UserName") will result in
UserID = "jsmith"

hope that helps.
 
WAR40K

I wouldn't use UserID = Environ("UserName") to keep record of logged users.|----> I 'm user JK in mdb, logging from my PC where Environ("UserName") = JerryKlmns, few minutes later I logg on from my collegues' PC where I, user JK in .mdb, have Environ("UserName") <> JerryKlmns! Who's logged on the mdb?

If you use Access2000 or higher and user-level security then CurrentUser() returns the mdb 's user name.

You could assign this to a Public variable like

Public TheUser As String

and on logg on
TheUser = CurrentUser() Or
TheUser = Environ("UserName")

Or use a GuessWho sub..

Code:
Sub GuessWho()
    
Dim rs As ADODB.Recordset
Dim S As String

    Set rs = CurrentProject.Connection.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    Do Until rs.EOF
        If Left(Trim(rs.Fields(1)), Len(Trim(rs.Fields(1))) - 1) <> .Properties("User ID") Then 
           S = S & "Computer Name: " & Left(Trim(rs.Fields(0)), Len(Trim(rs.Fields(0))) - 1) & "     User: " & Left(Trim(rs.Fields(1)), Len(Trim(rs.Fields(1))) - 1) & Chr(10)
        End If
        rs.MoveNext
    Loop
    If Len(S) = 0 Then S = "No other user is connected."
    MsgBox S, vbOKOnly, "Connected Users"
    rs.Close
    Set rs = Nothing

End Sub
 
Yeah, I always recommend that people use the built-in user-level security rather than create their own. It's quite powerful, once you invest the time to fully understand it.

---
Jeremy Wallace
METRIX Lead Developer
Fund for the City of New York
http:// metrix . fcny . org
 
Not to hijack this thread, but I have used the Security wizard on a couple of database applications I have built and it has been nothing but a source of frustration. Not every user has the same version of Access, there are problems added new users, permissions are a hassle, when all is said and done, it is really overkill for what I really need. My applications tend to be information management oriented, a way to create reports etc...More critical tasks are handled by the company's MRP system which is independent of my projects.

Thanks for the alternate method to capture user information.
 
Hi,

I have something very similar, I called the module within the Onload (of the login form). My user_id is public and i use a recordset to pull out the name and assign it to user_id. I have had no problems thus far. Once declared in the module, simply call the module from the onload of the login form.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top