creating a password, with three attempts allowed.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goldstar
    New Member
    • Jan 2008
    • 49

    creating a password, with three attempts allowed.

    Hello All,

    I am creating a system and would like to place a password when the system is open on the main form. i would like to be a code in vba that could be entered and should only allow three attempts before closing the form.

    Any ideas?

    Much Appreciated
  • jyoung2
    New Member
    • Jan 2008
    • 32

    #2
    in your form place a filed with visibilty set to no with a default of 0 call it whateve in this case fldAttempt. in your onclick event for the password check if the password is incorrect then

    Code:
    if me.fldAttempt > 2 then
       docmd.quit
    else
       me.fldAttempt = me.fldAttempt +1
    end if
    you could also do it with a global varible.

    Originally posted by goldstar
    Hello All,

    I am creating a system and would like to place a password when the system is open on the main form. i would like to be a code in vba that could be entered and should only allow three attempts before closing the form.

    Any ideas?

    Much Appreciated

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Here's a routine for doing this.

      Table name
      tblUsers

      Table Fields
      User_Name (Text datatype)
      User_Password (Text datatype)

      Form name
      LogInForm

      Form Controls
      txtUserName
      txtPassword
      cmdSubmitButton

      [CODE=vb]Private Static Sub cmdSubmitButton _Click()
      Dim Attempts As Integer

      If Me.txtPassword. Value = DLookup("[User_Password]", "tblUser", "[User_Name]='" & Me.txtUserName. Value & "'") Then
      'Continue to open database
      Else
      MsgBox "User Name and or Password Are Incorrect!", vbCritical, "Warning"
      Attempts = Attempts + 1
      Me.txtUserName. SetFocus
      If Attempts = 3 Then
      DoCmd.Close acForm, "LogInForm"
      End If
      End If
      End Sub
      [/CODE]

      Welcome to TheScripts!

      Linq ;0)>

      Comment

      • goldstar
        New Member
        • Jan 2008
        • 49

        #4
        Originally posted by missinglinq
        Here's a routine for doing this.

        Table name
        tblUsers

        Table Fields
        User_Name (Text datatype)
        User_Password (Text datatype)

        Form name
        LogInForm

        Form Controls
        txtUserName
        txtPassword
        cmdSubmitButton

        [CODE=vb]Private Static Sub cmdSubmitButton _Click()
        Dim Attempts As Integer

        If Me.txtPassword. Value = DLookup("[User_Password]", "tblUser", "[User_Name]='" & Me.txtUserName. Value & "'") Then
        'Continue to open database
        Else
        MsgBox "User Name and or Password Are Incorrect!", vbCritical, "Warning"
        Attempts = Attempts + 1
        Me.txtUserName. SetFocus
        If Attempts = 3 Then
        DoCmd.Close acForm, "LogInForm"
        End If
        End If
        End Sub
        [/CODE]

        Welcome to TheScripts!

        Linq ;0)>
        Thats, this works, but after 3 attempts the form does not close itself???
        would you have any idea

        Comment

        • goldstar
          New Member
          • Jan 2008
          • 49

          #5
          Originally posted by missinglinq
          Here's a routine for doing this.

          Table name
          tblUsers

          Table Fields
          User_Name (Text datatype)
          User_Password (Text datatype)

          Form name
          LogInForm

          Form Controls
          txtUserName
          txtPassword
          cmdSubmitButton

          [CODE=vb]Private Static Sub cmdSubmitButton _Click()
          Dim Attempts As Integer

          If Me.txtPassword. Value = DLookup("[User_Password]", "tblUser", "[User_Name]='" & Me.txtUserName. Value & "'") Then
          'Continue to open database
          Else
          MsgBox "User Name and or Password Are Incorrect!", vbCritical, "Warning"
          Attempts = Attempts + 1
          Me.txtUserName. SetFocus
          If Attempts = 3 Then
          DoCmd.Close acForm, "LogInForm"
          End If
          End If
          End Sub
          [/CODE]

          Welcome to TheScripts!

          Linq ;0)>
          Thats great!!! it works a beauty!!!

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Glad we could help!

            Linq ;0)>

            Comment

            • goldstar
              New Member
              • Jan 2008
              • 49

              #7
              Originally posted by missinglinq
              Glad we could help!

              Linq ;0)>
              is there a way to turn the letters entered into stars so it is not possible to see what is being entered into the system? ****

              Comment

              • jaxjagfan
                Recognized Expert Contributor
                • Dec 2007
                • 254

                #8
                Originally posted by goldstar
                is there a way to turn the letters entered into stars so it is not possible to see what is being entered into the system? ****
                Set the Input mask to the field as PASSWORD.

                Comment

                • goldstar
                  New Member
                  • Jan 2008
                  • 49

                  #9
                  Originally posted by jaxjagfan
                  Set the Input mask to the field as PASSWORD.
                  thanks works a treat!!!

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32668

                    #10
                    Originally posted by goldstar - Post #4
                    Thats, this works, but after 3 attempts the form does not close itself???
                    would you have any idea
                    Originally posted by goldstar - Post #5
                    Thats great!!! it works a beauty!!!
                    Curious as to what happened in-between.

                    My reading of the code is that the Dim line should be changed to Static if the count is to persist between calls (clicks of the Command Button). An alternative would be to define it outside of the procedure (as Private).

                    Comment

                    • missinglinq
                      Recognized Expert Specialist
                      • Nov 2006
                      • 3533

                      #11
                      I hadn't used Static in ages, and had to go to help for a refresher. I was thinking it was part of the Dim statement, too, but that's not true, at least not in ACC2003. Declaring the sub Static persists the value of any variables declared within the sub, as long as the form is open.

                      As to what happened between # 4 and # 5, I call it the NIDYID effect! (No It Doesn't, Yes It Does!) When I know the code is valid, I just wait. The OP usually gets it sussed out. Probably a typo!

                      Linq ;0)>

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32668

                        #12
                        Nice one Link ;)
                        I didn't even know (or I suppose I must have known at some time - having been through help for such things a few times - but certainly didn't remember even when reminded) that a procedure could also be defined as static, and what effect that had on the internally DIMmed variables. I think I may even prefer your solution :)

                        PS. I've just reread your posts and saw a possible reason why I missed that part of the first line. Yellow on white is hardly the best contrast factor available - hence I never use [ CODE = VB ] in my posts (it's optional of course). You lose more than you gain for me.

                        Comment

                        • missinglinq
                          Recognized Expert Specialist
                          • Nov 2006
                          • 3533

                          #13
                          I always assumed "Please use code tags" meant "Please use appropriate code tags!" I agree a wiser choice of colors could have been made! The colors aren't bad on my laptop screen, but on my secondary monitor, an elderly HP M90, they're somewhat faded. And, of course, sad to say, I'm forced to use my secondary monitor most of the time.

                          Linq ;0)>

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32668

                            #14
                            No, no.
                            We don't choose to enforce the basic ones as some love what the targetted ones can do. My personal preference is for the basic ones, but I regret losing the benefit of the highlighting of particular sections. Bear in mind too, that the parsing is not perfect and some items are incorrectly coloured.

                            Comment

                            • goldstar
                              New Member
                              • Jan 2008
                              • 49

                              #15
                              Hello All,

                              The code above works fine, Is there a way to attach a button incase the employee was to forget their password,

                              I am currently trying to have a button on my home form saying 'forgot password'
                              When this is pressed a list of questions appear within a combo box and when an answer has been entered, they are logged into the menu form?

                              Regards

                              Comment

                              Working...