Private Sub cmdSubmit_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb()
strSQL = "SELECT * FROM tblEmployee WHERE [EmployeeID] = " & Me.cboLogin.value
'Backdoor
If IsNull(Me.cboLogin) And Me.txtPassword.value = "admin" Then
On Error GoTo Err_bDisableBypassKey_Click
'This ensures the user is the programmer needing to disable the Bypass Key
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
"Please key the programmer's password to enable the Bypass Key."
strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
If strInput = "admin" Then
SetProperties "AllowBypassKey", dbBoolean, True
Beep
MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & "The Shift key will allow the users to bypass the startup & options the next time the database is opened.", vbInformation, "Set Startup Properties"
Else
Beep
SetProperties "AllowBypassKey", dbBoolean, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & "The Bypass Key was disabled." & vbCrLf & vbLf & "The Shift key will NOT allow the users to bypass the & startup options the next time the database is opened.", vbCritical, "Invalid Password"
Exit Sub
End If
Exit_bDisableBypassKey_Click:
DoCmd.Quit
Err_bDisableBypassKey_Click:
MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
Resume Exit_bDisableBypassKey_Click
Else
'CHECKING FOR NULLS
If IsNull(Me.cboLogin) Then
MsgBox Mssg1, vbCritical, Title1
Me.cboLogin.SetFocus
Call CheckLogAttempts
ElseIf IsNull(Me.txtPassword) Then
MsgBox Mssg1, vbCritical, Title1
Me.txtPassword.SetFocus
Call CheckLogAttempts
'VALIDATING PASSWORD
Else
If Me.txtPassword.value = DLookup("Password", "tblEmployee", "[EmployeeID]=" & Me.cboLogin.value) Then
'PASSING VARIABLES TO DB
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
With user
.CurrentUser = rst.Fields("EmployeeID")
End With
rst.Close
'Open Appropriate Home Form
If Me.txtPassword.value = "changeme" Then
DoCmd.OpenForm "frmchangePassword", acNormal, , "EmployeeID=" & Me!cboLogin, acFormEdit, acDialog
DoCmd.Close acForm, "frmbackground", acSaveNo
Else
DoCmd.OpenForm "frmhome", acNormal
DoCmd.Close acForm, "frmBackground", acSaveNo
Me.Visible = False
End If
'Close Login Form
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
Call CheckLogAttempts
End If
End If
End If
End Sub
Private Sub CheckLogAttempts()
If lngLogAttempts >= 2 Then
MsgBox " It appears you are having trouble logging on. " & Chr(13) & "Please contact your System Administrator " & "for assistance. ", vbCritical, Title1
DoCmd.Quit
Else
lngLogAttempts = lngLogAttempts + 1
End If
End Sub