Can someone review my code and see why my Log-In userform code will not work properly? I can't get the Log-In form to redisplay each time the user inputs the wrong USERNAME and PASSWORD. After the inital log-in attempt, code loops two more time, but never re-displays the log-in form for the second and third attempts.
I'm sure it's something very simple I'm missing, but I can't figure it out. Please help.
frmLogIn - Name of the form that loads when the workbook opens.
frmEmployee - Form that is displayed after correct log-in information is entered.
Private Sub cmdLogIn_Click()
Dim intCounter As Integer
Dim x As Integer
x = 1
intCounter = 3
Do Until x > intCounter
If txtUserName <> "Admin" And txtPassword <> "admin" Then
MsgBox "Invalid UserName or Password. Please enter valid log-in information", _
vbCritical, "Invalid Log-In: Attempt #" & x
x = x + 1
If x > intCounter Then
MsgBox "Three Unsuccessful Log-In Attempts." + vbNewLine + _
"Contact System Adminstrator for Password Reset", vbCritical, "Invalid Log-In"
Unload Me
Exit Sub
Else
Me.txtUserName = ""
Me.txtPassword = ""
Me.txtUserName.SetFocus
End If
Else
MsgBox "Log-In Successful", , "Successful Log-In"
Unload Me
frmEmployee.Show
End If
Loop
End Sub
Tried putting the statement EXIT SUB after the me.txtUserName.SetFocus in the nested If Statement, and it still does not work.
I'm sure it's something very simple I'm missing, but I can't figure it out. Please help.
frmLogIn - Name of the form that loads when the workbook opens.
frmEmployee - Form that is displayed after correct log-in information is entered.
Private Sub cmdLogIn_Click()
Dim intCounter As Integer
Dim x As Integer
x = 1
intCounter = 3
Do Until x > intCounter
If txtUserName <> "Admin" And txtPassword <> "admin" Then
MsgBox "Invalid UserName or Password. Please enter valid log-in information", _
vbCritical, "Invalid Log-In: Attempt #" & x
x = x + 1
If x > intCounter Then
MsgBox "Three Unsuccessful Log-In Attempts." + vbNewLine + _
"Contact System Adminstrator for Password Reset", vbCritical, "Invalid Log-In"
Unload Me
Exit Sub
Else
Me.txtUserName = ""
Me.txtPassword = ""
Me.txtUserName.SetFocus
End If
Else
MsgBox "Log-In Successful", , "Successful Log-In"
Unload Me
frmEmployee.Show
End If
Loop
End Sub
Tried putting the statement EXIT SUB after the me.txtUserName.SetFocus in the nested If Statement, and it still does not work.