Another Access 2007 Logon Question

Hi everyone,

I decided to ask a new question on the Access 2007 LOGON.  I need to have a msg box appear when a password is entered that is not in the database when a user enters one.

My coding:

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.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
        End If

'Close logon form and open splash screen
    If lngMyEmpID = "1" Or lngMyEmpID = "2" Or lngMyEmpID = "3" Then
       
  DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Startup Screen"

     Else
        DoCmd.OpenForm "StartupScreen2"
 
End If


     
     
   
   
   
   
'If User Enters incorrect password 3 times database will shutdown
   
       
   
    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


Where can I put some coding to chek for the incorrect entery of a password that does not exist in the sstem when entered by a user?
LOGON-FORM-001.jpg
jjc9809Asked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:


 'use this codes instead

'Check value of password in tblEmployees to see if this matches value chosen in combo box

 
     if nz(DLookup("strEmpPassword", "tblEmployees","[strEmpPassword]='" & Me.txtPassword & "' And  [lngEmpID]=" & Me.cboEmployee.Value),"") <> "" Then
     
        lngMyEmpID = Me.cboEmployee.Value
      else

      Msgbox "Message here"

      exit sub

     End If
0
 
jjc9809Author Commented:
Thanks

It works real good.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.