I have a login script but I cannot see why there is an error, here is the code:
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box - works fine
If IsNull(Me.cmboLogon) Or Me.cmboLogon = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cmboLogon.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box - works fine
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 tblStaff to see if this
'matches value chosen in combo box - Errors
'This next bit is the section that gets highlighted in my debugger as being wrong.
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblStaff", "[lngMyEmpID]=" & Me.cmboLogon.Value) Then
lngMyEmpID = Me.cmboLogon.Value
'Close logon form and open switchboard
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Switchboard"
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 admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
txtPassword - password field in form
strEmpPassword - password field in table
tblStaff - table of users ids & passwords
lngMyEmpID - userids in table
cmboLogon - Logon id field in form (drop down list)
Can anyone help?
Thanks Angel
Private Sub cmdLogin_Click()
'Check to see if data is entered into the UserName combo box - works fine
If IsNull(Me.cmboLogon) Or Me.cmboLogon = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cmboLogon.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box - works fine
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 tblStaff to see if this
'matches value chosen in combo box - Errors
'This next bit is the section that gets highlighted in my debugger as being wrong.
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblStaff", "[lngMyEmpID]=" & Me.cmboLogon.Value) Then
lngMyEmpID = Me.cmboLogon.Value
'Close logon form and open switchboard
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Switchboard"
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 admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
txtPassword - password field in form
strEmpPassword - password field in table
tblStaff - table of users ids & passwords
lngMyEmpID - userids in table
cmboLogon - Logon id field in form (drop down list)
Can anyone help?
Thanks Angel