Help With Login attempts!

JBurlison

Registered User.
Local time
Today, 18:37
Joined
Mar 14, 2008
Messages
172
The login works Great but Login attempts dose not im still new to VB so i must be overlooking something.


Code:
Private Sub Ok_Click()

Dim LogonAttempts As Integer
Dim SaiCurrentUser As String

SaiCurrentUser = ""
LogonAttempts = 0

        If Me.Password.Value = DLookup("[Password]", "[User Name]", "[User Name] = '" & Me.User_name & "'") Then
        
            SaiCurrentUser = [User Name]
            DoCmd.Close acForm, "Login Screen", acSaveNo
            DoCmd.OpenForm "Switchboard"
                
        Else
        
            LogonAttempts = LogonAttempts + 1
            
          MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
                "Invalid Entry!"
            Me.Password.SetFocus
            Me.Password.Value = ""
          
        If LogonAttempts > 3 Then
            MsgBox "You do not have permission to access this database.Please contact your database administrator."
            Application.Quit
    
       End If
             
        
        End If
    
    
    
    End Sub
 
You're missing the fact that your integer will never get past 1. When you use DIM it initializes the variable on each time it fires. So, you need to change

Dim LogonAttempts As Integer

to

Static LogonAttempts As Integer
 
OHHHHHHHhhh lol thanks bob! also i noticed that i was setting it back to 0 every time too lol.
 
GladWeCouldHelp.png
 

Users who are viewing this thread

Back
Top Bottom