I've been doing research on Login Userforms and have come up with a code variation similar to coding trend.
However, I am having an issue clearing the previous information, allowing the user to reenter their password before the loop continues. (i.e. the user inputs "password", receives an invalid password message, then reenters their password.)
As the code is written now, the user recieves three succesive messages and the application closes, before they ever get a chance to reenter the password. My code is below...hope my issue is clear. If not, let me know. THANKS!
Private Sub CommandButton1_Click()
UserName = ComboBox1.Value Password = TextBox2.Value Dim intLogonAttempts As Integer
For intLogonAttempts = 0 To 3 If IsNull(UserName) Or UserName = "" Then MsgBox ("User Name is a required field.") ComboBox1.SetFocus Exit Sub End If 'Check to see if data is entered into the password box If IsNull(Password) Or Password = "" Then MsgBox ("Password is a required field.") TextBox2.SetFocus Exit Sub End If 'Check value of password in tblEmployees to see if this matches value chosen in combo box If UserName = "Administrator" And Password = "password" Then ...Do This... ElseIf UserName = "McNitro" And Password = "password" Then ...Do That...
Else MsgBox ("Password Invalid. Please Try Again") TextBox2.SetFocus End If 'If User Enters incorrect password 3 times database will shutdown If intLogonAttempts < 3 Then TextBox.Value = ""
Else: NoAccessQ = MsgBox("You do not have access to this database. Please contact your system administrator.", vbCritical, "Access to Access is Restricted!") Application.Quit Exit Sub End If Next intLogonAttempts
August 18, 2009 8:52 PM
August 21, 2009 10:14 PM