Hi all,
I am in need of help; I built a login form with a drop down list showing the names that I want to log in. The names are listed in a table cal tblEmployees. Everything works fine and they are able to log in but what I need to happen now is that when they are on a form it shows their name (no the computer user but the one who logged in database) so i can capture if they make any changes and also they kow who is logged in.
Below is the code that works for them to log in, i just don't know how to pass their name on to forms etc:
Thanks in advance
I am in need of help; I built a login form with a drop down list showing the names that I want to log in. The names are listed in a table cal tblEmployees. Everything works fine and they are able to log in but what I need to happen now is that when they are on a form it shows their name (no the computer user but the one who logged in database) so i can capture if they make any changes and also they kow who is logged in.
Below is the code that works for them to log in, i just don't know how to pass their name on to forms etc:
Code:
Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub
Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtAccess.Value = DLookup("strAccess", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open forms
If Me.txtAccess.Value = "Admin" Then
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Switchboard"
ElseIf Me.txtAccess.Value = "User" Then
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "User_Switchboard"
End If
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Thanks in advance