user log in (1 Viewer)

icemonster

Registered User.
Local time
Today, 05:34
Joined
Jan 30, 2010
Messages
502
hello.

lately i have been using the getusername (to get the username of the current pc user) to check the username and password.

what i want is, to have a log in screen that can let yo type your username and password at the same time recording or storing the current user because i have a form that has a field currentuser and i want that field to fill the current user if any changes are made.

is there someone who understands and perhaps enlighten me? thank you.
 

icemonster

Registered User.
Local time
Today, 05:34
Joined
Jan 30, 2010
Messages
502
here's the code i am using.

Code:
Option Compare Database
Option Explicit

'Module name    : clsLogin
'Description    : This class module deals with the authenication of a user by checking their
'               : login details on the user table.
'Developed By   : Rob Boyle
'Example        : See form (frmLogin) example for full instructions and example code

Public strIusername As String
Public strIpassword As String
Public strTable As String
Public strUsernameField As String
Public strPasswordField As String

Public Property Let Username(strParam As String)
    'Accepts a username for searching
    strIusername = strParam
End Property

Public Property Get Username() As String
    'Return username
    Username = strIusername
End Property

Public Property Let Password(strParam As String)
    'Accepts a username for searching
    strIpassword = strParam
End Property

Public Property Get Password() As String
    'Return password
    Password = strIpassword
End Property

Public Property Get ValidUser() As Boolean
    'Returns boolean value depending on whether user is on system or not
    If ConfirmUser Then
        'User is on system
        ValidUser = True
    Else
        ValidUser = False
    End If
End Property

Public Property Let Table(strParam As String)
    'Set table var
    strTable = strParam
End Property

Public Property Let UsernameField(strParam As String)
    'Gets the username field from the table
    If IsNull(strParam) Then
        MsgBox "Please supply the username field from the table!   ", vbExclamation, "No username field supplied"
        Exit Property
    End If
    
    'Set username var
    strUsernameField = strParam
End Property

Public Property Let PasswordField(strParam As String)
    'Set username var
    strPasswordField = strParam
End Property

Private Function ConfirmUser() As Boolean
    'Confirms user details by checking user table
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    With rs
        .ActiveConnection = CurrentProject.Connection
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Source = "SELECT * FROM " & strTable & " WHERE " & strUsernameField & " = '" & strIusername & "' AND " & _
            strPasswordField & " = '" & strIpassword & "'"
        .Open

        'Check if details are valid
        If .RecordCount = 0 Then
            'User is not on the system
            ConfirmUser = False
            GoTo CloseRS
        End If
        
        'Set any additional global variables here eg.
        'strAccesslevel = .Fields("AccessLevel")
        
        'User is on the system
        ConfirmUser = True
        
CloseRS:
        'Close the connection
        .Close
    End With

    'Reset the recordset variable
    Set rs = Nothing
End Function

i cant figure out how to be able to store the current user so that i can call that current user to the form that records whomever created/changed a data. please help me.
 

smig

Registered User.
Local time
Today, 13:34
Joined
Nov 25, 2009
Messages
2,209
you can store the value in a public variable
you will have to use a function to call this variable if you want to use it in a query

if you want to save it for the next load of your application you can save it to the registery
 

icemonster

Registered User.
Local time
Today, 05:34
Joined
Jan 30, 2010
Messages
502
how do you propose i do that? i dont need it in a query i need it to be in my form when changes are made and saved.
 

Tim L

Registered User.
Local time
Today, 11:34
Joined
Sep 6, 2002
Messages
414
As a quick fix I've learnt how to use VBA, in the On Current event for a form, to set the value of a text box to the logged on user name, e.g:
Code:
me.txtBoxName.value = Environ("UserName")
You should then be able to use the data as you see fit.

Have a look at this thread, which might help. I was not aware of the limitations mentioned in the thread above. I guess that whether the limitation metioned is an issue will depend on whether there are likely to be other applications which may change the UserName or whether there could be a user who might deliberately try to foil the system. An individual needs analysis will need to be made based on your own circumstances.
 

Users who are viewing this thread

Top Bottom