Login Form Problem

joesstlouis

Registered User.
Local time
Today, 04:37
Joined
Feb 20, 2006
Messages
10
I'm currently having issues with my login script on my opening form... it's supposed to close the application if it gets 3 failed attempts, but it's not closing... it just keeps giving me a popup and letting me type the password again. Here's the Code:

'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("Password", "tblLogin", "[UserID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "frmMainMenu"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact admin.", vbCritical, "Restricted Access!"
Application.Quit
End If
 
When are you calling this code? Particularly the line:

Code:
intLogonAttempts = intLogonAttempts + 1

Surely that needs to go in this statement:

Code:
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

So that the count actually increases?

Bobadopolis
 
Sorry I'm a noob to this... how should I go about incorporating that?
 
So you want to increment the login attempts when the user fails to type the correct password:

Code:
'This is the code that runs when the user types the wrong password:
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
intLogonAttempts = intLogonAttempts + 1
Me.txtPassword.SetFocus
End If

It would be much easier though if you could paste all the actual code so that I can see when events are firing...

Bobadopolis
 
That is pretty much all the code on the page minus a close button and a setfocus
 
I take it then this runs on the AfterUpdate event of the password box? Have u declared intLogonAttempts somewhere in the event?

Code:
Dim intLogonAttempts as Integer
intLogonAttempts = 0
 
Better still use a hidden text box (I don't like variables in these kind of circumstances). Make it's default value 0 and increment accordingly:

Code:
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
me.txtLogonAttempts = me.txtLogonAttempts + 1
Me.txtPassword.SetFocus
End If
 

Users who are viewing this thread

Back
Top Bottom