title: Creating Login form on Access using VBA
body: <p>I am trying to create a login for my Access db, but I can't get it to work. Here is my code (keep in mind "Preparer" is the name of the table holding username and password info:</p>
  
  <pre><code>Private Sub Command1_Click()
  
      If IsNull(Me.txtLogin) Then
  
          MsgBox "Please Enter Login", vbInformation, "Need ID"
          Me.txtLogin.SetFocus
  
      ElseIf IsNull(Me.txtPassword) Then
  
          MsgBox "Please Enter Password",vbInformation, "Need Password"    
          Me.txtPassword.SetFocus
  
      Else
  
          If ((IsNull(DLookup("Login","Preparer","Login='&amp; Me.txtLogin.Value &amp;'"))) or _
          (IsNull(DLookup("Password","Preparer","Password='&amp; Me.txtPassword.Value &amp;'")))) Then
  
              MsgBox "Incorrect Login or Password"
  
          Else
  
              DoCmd.Close    
              MsgBox "Success"
  
              DoCmd.OpenForm "Master"
  
          End If
  
      End If
  
  End Sub
  </code></pre>
  
  <p>The first two parts work so if login or password is blank it gives the correct error message, but whenever I put a login and password, even if they are correct (i.e. they exist in the preparer table) it gives me the "Incorrect Login or Password"</p>
  
  <p>I'm assuming the problem is in the code here:</p>
  
  <pre><code>If ((IsNull(DLookup("Login","Preparer","Login='&amp; Me.txtLogin.Value &amp;'"))) or _
      (IsNull(DLookup("Password","Preparer","Password='&amp; Me.txtPassword.Value &amp;'")))) Then
  
      MsgBox "Incorrect Login or Password"
  </code></pre>
  
  <p>Anyone understand why I can't get to the bottom else statement?</p>