Counter for failed attempt is not working

raj08536

Active Member
Joined
Aug 16, 2007
Messages
322
Office Version
  1. 365
Platform
  1. Windows
My counter LoginFailedCount is not counting. Can any Guru help me?

Private Sub Command8_Click()

Dim strPassword As String
Dim strExistPassword As String
Dim strLogin As String
Dim LoginFailedCount As Double

If IsNull(Me.txtPassword) Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Else
strPassword = Me.txtPassword.Value
strLogin = "'" & Me.txtuser.Value & "'"
strExistPassword = DLookup("password", "tblstaff", "[login] = " & strLogin)

If strExistPassword = strPassword Then
DoCmd.Close acForm, "frmmenu1", acSaveNo
DoCmd.OpenForm "frmmenu", acNormal, , , , acHidden
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
LoginFailedCount = LoginFailedCount + 1
If LoginFailedCount > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", vbCritical, "Restricted Access!"
Application.Quit
End If


End If


End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You need to set up a loop to run the password check.
Untested, but try...
Code:
Private Sub Command8_Click()
    Dim strPassword As String
    Dim strExistPassword As String
    Dim strLogin As String
    Dim LoginFailedCount As Double
    
    If IsNull(Me.txtPassword) Then
        MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        Me.txtPassword.SetFocus
    Else
        strPassword = Me.txtPassword.Value
        strLogin = "'" & Me.txtuser.Value & "'"
        strExistPassword = DLookup("password", "tblstaff", "[login] = " & strLogin)
    
        If strExistPassword = strPassword Then
            DoCmd.Close acForm, "frmmenu1", acSaveNo
            DoCmd.OpenForm "frmmenu", acNormal, , , , acHidden
        Else
            Do
                MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
                Me.txtPassword.SetFocus
                LoginFailedCount = LoginFailedCount + 1
                If LoginFailedCount > 3 Then
                    MsgBox "You do not have access to this database.Please contact admin.", vbCritical, "Restricted Access!"
                    Application.Quit
                End If
            Loop
        End If
            
    End If
End Sub

Denis
 
Upvote 0
it start working but I have to announce my variable on the top....
 
Upvote 0
Actually, you should change this:

Dim LoginFailedCount As Double

to this:

Static LoginFailedCount As Double

As the DIM would reset it each time you run it.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top