Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    287

    Unanswered: Password Attempts

    Hi all,
    I have a password form that works fine but I want the ability to add amount of attempts so after the 3rd attempt the program errors.

    Here's my code which doesn't appear to be working.. any suggestions please..

    Code:
    Public Sub cboPassword_AfterUpdate()
    Dim pwnum
    ProgPW = DLookup("Password", "Password", "[ID] = 1")
    
        If cboPassword = ProgPW Then
              DoCmd.Close
              DoCmd.OpenForm "Editor"
            Else
            If pwnum < 2 Then
            MsgBox "The Password you entered is incorrect!" & vbCrLf & "Please contact your system administrator " & vbCrLf & pwnum, vbCritical, "Incorrect Password Entered"
            pwnum = pwnum + 1
                Else
                If pwnum >= 3 Then
                MsgBox "3 Login Attempts" & vbCrLf & "Program will Exit " & vbCrLf & pwnum, vbCritical, "Incorrect Password Entered"
                Else
            End If
        End If
    End If
    
                
    End Sub
    
    
    Public Sub Form_Open(Cancel As Integer)
    Dim pwnum
    pwnum = 0
    End Sub

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Public Sub cboPassword_AfterUpdate()
    Dim pwnum <- Every time they enter a password, this is getting regenerated. Remove this from here. Maybe put it after the line right after "Option Compare Database" and dim it as an integer (ie Dim pwnum as integer).
    ProgPW = DLookup("Password", "Password", "[ID] = 1")

    If cboPassword = ProgPW Then
    DoCmd.Close
    DoCmd.OpenForm "Editor"
    Else
    If pwnum < 2 Then
    MsgBox "The Password you entered is incorrect!" & vbCrLf & "Please contact your system administrator " & vbCrLf & pwnum, vbCritical, "Incorrect Password Entered"
    pwnum = pwnum + 1
    Else
    If pwnum >= 3 Then
    MsgBox "3 Login Attempts" & vbCrLf & "Program will Exit " & vbCrLf & pwnum, vbCritical, "Incorrect Password Entered"
    Else
    End If
    End If
    End If
    End Sub

    Public Sub Form_Open(Cancel As Integer)
    Dim pwnum <- remove from here and put Dim pwnum as integer in line after "Option Compare Database"
    pwnum = 0
    End Sub
    Last edited by pkstormy; 06-15-07 at 11:38.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Mar 2004
    Posts
    287
    Nevermind, here's how I got it working - I created an unbound box on the form called pwnum and default value 0

    Then here's my code;
    Code:
    Public Sub cboPassword_AfterUpdate()
    ProgPW = DLookup("Password", "Password", "[ID] = 1")
    
        If cboPassword = ProgPW Then
              DoCmd.Close
              DoCmd.OpenForm "Editor"
            Else
            If [pwnum] < 2 Then
            [pwnum] = (pwnum) + 1
            MsgBox "The Password you entered is incorrect!" & vbCrLf & "Attempt Number: " & pwnum, vbCritical, "Incorrect Password Entered"
                Else
                [pwnum] = (pwnum) + 1
                MsgBox "The Password you entered is incorrect!" & vbCrLf & "You have exceeded the maximum attempts" & vbCrLf & "Attempt Number: " & pwnum, vbCritical, "Incorrect Password Entered"
                DoCmd.Close
                DoCmd.OpenForm "Switchboard"
            End If
        End If
               
    End Sub
    Hopefully this will help others...

    It goes back to my main switchboard form after the 3rd attempt although you can just easier quit the application at this stage.

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Either way works. You may want to change...

    if me!pwnum < 2 then...

    and...

    [pwnum] = (pwnum) + 1

    to

    me!pwnum = me!pwnum + 1
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you probably would have got your original code to work had you DIMmed the pwnum as a STATIC variable in the after update code
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •