I am trying to build a login screen where it prompts for a password only for a certain user. I have gotten all this to work except for one issue. On the loop, unless they enter the correct result, even if they click cancel or the X, they can not leave the loop. How would I modify the code to allow for the cancel to close the InputPw message box and go back to the login form.
Thanks,
Private Sub LoginUser_Click()
un = LoginUser 'Combo drop box listing users
If un = "sw" Then 'un is public variable for logged in user initials. If username matches prompt for password
InputPw 'Public Function for input box to return password as string
Do Until pw = "aa" 'expected password
MsgBox "Incorrect Password. Please try again", vbOKCancel
InputPw
Loop 'keep prompting for password until correct
DoCmd.Close 'if password is correct close login screen
DoCmd.OpenForm "frmMenu", acNormal, , , , acNormal 'Open Main Menu Screen
End If
If un <> "sw" Then
DoCmd.Close
DoCmd.OpenForm "frmMenu", acNormal, , , , acNormal
End If
End Sub