+ Reply to Thread
Results 1 to 11 of 11

Thread: Login Dialog not working

  1. #1
    Registered User
    Join Date
    10-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2010 (mac)
    Posts
    10

    Login Dialog not working

    The part of three failed attempts is not working. Please help with this. Thank you!

    Private Sub cmd_ok_Click()
    
    Dim attempt As Integer
    Dim valid As Boolean
    
    attempt = 0
    valid = False
    
    Do
        attempt = attempt + 1
        If Me.cbo_User.Column(2) = Me.txt_Password Then
            valid = True
            MsgBox "Password accepted"
            DoCmd.OpenForm "Student", acNormal
            DoCmd.Close acForm, "Login"
        Else
            valid = False
             MsgBox "Wrong password entered." & _
            vbCrLf & "Please re-enter password.", _
            vbExclamation, "Invalid Password"
            Me.txt_Password.SetFocus 'places the cursor in password control
            Exit Sub
        End If
        
    Loop Until (valid = True) Or (attempt >= 3)
    
    If attempt >= 3 Then
        MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
        Exit Sub
    End If
        
    
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    1,946

    Re: Login Dialog not working

    Without testing, I think its this line:

    Loop Until (valid = True) Or (attempt >= 3)
    Try removing the paranetheses. If not, then please explain what the problem is exactly?

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    10-28-2011
    Location
    UK
    MS-Off Ver
    Excel 2010 (mac)
    Posts
    10

    Re: Login Dialog not working

    The problem is that after the 3rd attempt, the message box" "You do not have access to this database. Please contact your system administrator." does not come up.

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    1,946

    Re: Login Dialog not working

    This might sound like a dumb question, but does it come up after the fourth attempt or does it never come up at all.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    1,946

    Re: Login Dialog not working

    Try changing the way the do... loop works:

    Do While valid = False And attempt < 3
    Loop
    abousetta

    P.S. It would help if you could upload a dummy workbook to test on.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Login Dialog not working

    I believe you need to remove the Exit Sub from the Else part of the code. It is defeating the purpose of the loop.
    Good luck.

  7. #7
    Registered User
    Join Date
    04-19-2010
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Login Dialog not working

    I'm going to agree with OnError. Exit sub in your else block is causing you to exit and when you come back into the sub, so your attempt variable is reset to 0. Which kind of makes me think that you need to declare the attempt variable as static. You would also need to initialize that variable on the form load event to 0.

    My suggestion,
    
    Static attempt as integer
    Dim valid as Boolean
    
    If attempt >= 3 Then
         'messagebox and events for no access
         cmd_ok.enabled = false 'This will cause them to have to reopen the form to submit again.
    else
         'check the password
         if password = me.txtPassword Then
              valid = true
         else
              me.txtPassword.value = ""
              'messagebox and events for this
              attempt = attempt + 1
        End If
    End If
    I'm really leaning at you have a variable scope issue. Each time the user clicks go, the attempts are reset to 0. With static, the number should be saved until the form is closed and is re-initialized.

  8. #8
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Login Dialog not working

    If you do not exit the sub, there should be no issue with the counter being reset. If you use a static variable, then having got the password wrong three times, you would only get one attempt the next time. Equally, having used the code correctly three times, you would only have one attempt next time - unless you restart the application.
    Good luck.

  9. #9
    Registered User
    Join Date
    04-19-2010
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Login Dialog not working

    I was assuming that the user was clicking the button again to enter the password that would re-fire the event. Just setting the focus to the textbox wont do anything but point the user to the wrong input. They still have to resubmit the new information somehow. Having it inside a loop esentially doesn't do anything. I can only assume that without exit sub it would hit the 3 attempts quickly because there isn't anything stopping execution when the event fires, while the user enters new data. Unless .setFocus does something I am not aware of for validation. If .setFocus does halt execution then yes. Getting rid of exit sub will work.

    To fix the attempts you could reset the static variable to =0 after a sucessful login then you always start fresh after a good login.

  10. #10
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Login Dialog not working

    I think you are correct - at least that is how it ought to be working. I confess I did not really examine what the original loop was doing - I had input boxes in my mind for some reason. So yes I think you would need something like
         if password = me.txtPassword Then
              valid = true
              attempt = 0
    Good luck.

  11. #11
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,621

    Re: Login Dialog not working

    Maybe this will helpPASSWORD FORM6.xls
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0