Using a pop-up box to input a password?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • greeni91
    New Member
    • Nov 2009
    • 61

    Using a pop-up box to input a password?

    Hi Guys,

    I am looking for a way to bring up an input box to insert a password to unlock a field in a form. I am trying to do it so that if you tick a tick box, "ONTick" then the field will lock, but when someone tries to untick the box it prompts for a password. I don't have the slightest clue where to start and have been staring at a For Dummies book for a good few days now.

    Useful Info:

    Field I am trying to lock is called "OperatorNa me"

    The tick box is called "ONTick"


    Thanks in Advance for any help

    /Sandy
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Here's code to get you started, Sandy:

    Code:
    Private Sub Form_Current()
    If Me.ONTick = True Then
      Me.OperatorName.Locked = True
     Else
      Me.OperatorName.Locked = False
     End If
    End Sub
    Code:
    Private Sub ONTick_AfterUpdate()
     If Me.ONTick = True Then
      Me.OperatorName.Locked = True
     Else
      Me.OperatorName.Locked = False
     End If
    End Sub
    Code:
    Private Sub ONTick_Click()
     
    Dim PWord As String
    
    Dim FixedPassword As String
    FixedPassword = "Unlock"
     
     If ONTick.OldValue = -1 Then
      PWord = InputBox("Enter Password to Unlock Operator Name Field", "Enter Password")
        If PWord = FixedPassword Then
         Me.OperatorName.Locked = False
         Me.ONTick = -1
        Else
         MsgBox "Password Incorrect!"
         ONTick.Value = ONTick.OldValue
         Me.OperatorName.Locked = True
       End If
     End If
    End Sub
    Now this example uses a hardwired password, Unlock, as assigned to FixedPassword near the beginning of the ONTick_Click() sub. You can modify this code to take variable passwords, if you need to, possibly checking them against passwords in a tbale.

    Good luck!

    Linq ;0)>

    Comment

    • greeni91
      New Member
      • Nov 2009
      • 61

      #3
      Hi Linq,

      Thanks for the reply...I am so close to getting this now it's unreal. Thanks a Bunch.

      I still have a very minor problem though and I've tried rewriting some of the code to help but this is the closest I got to perfect.

      Code:
      Private Sub ONTick_AfterUpdate()
       
       If Me.ONTick = True Then
        Me.OperatorName.Enabled = True
       Else
        Me.OperatorName.Enabled = False
       End If
       
      Dim PWord As String
        
      Dim FixedPassword As String
      FixedPassword = "Unlock"
        
       If ONTick.OldValue = -1 Then
        PWord = InputBox("Enter Password to Unlock Operator Name Field", "Enter Password")
          If PWord = FixedPassword Then
           Me.OperatorName.Enabled = True
           Me.ONTick = 0
          Else
           MsgBox "Password Incorrect!"
           ONTick.Value = ONTick.OldValue
           Me.OperatorName.Enabled = False
         End If
       End If
       
      End Sub
      As you can see I moved all the stuff into the after update field and I have put everything into subfrom_current as well:

      Code:
      If Me.ONTick = True Then
        Me.OperatorName.Enabled = False
       Else
        Me.OperatorName.Enabled = True
       End If
        
      Dim PWord As String
        
      Dim FixedPassword As String
      FixedPassword = "Unlock"
        
       If ONTick.Value = -1 Then
        PWord = InputBox("Enter Password to Unlock Operator Name Field", "Enter Password")
          If PWord = FixedPassword Then
           Me.OperatorName.Enabled = True
      Else
           MsgBox "Password Incorrect!"
           ONTick.Value = ONTick.OldValue
           Me.OperatorName.Enabled = False
         End If
       End If
      The problem I am having is when I click on the tick box the tick appears and I input my password as wanted but when the password has been inputted the tick vanishes. What I was wanting to do is keep the tick visible so that when I untick it the box, OperatorName just locks without the password prompt.

      What I have to do just know is retick the box and cancel to get the messagebox prompt to lock the field.

      Any help on this would be great.

      Thanks,

      /Sandy

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        If you used the exact code I gave you, in the events the code was originally in, instead of trying to get clever and "consolidat e" the code into the AfterUpdate event, it would work!

        And please, when posting code, hit the "Go Advanced" button at the bottom of the editing screen, select the code then hit the pound sign icon (#) to place code tags around it. It makes it much easier for us to read.

        Linq ;0)>

        Comment

        • greeni91
          New Member
          • Nov 2009
          • 61

          #5
          I had to change the code you gave me to tailor for my needs and I have been told countless times by people to use only one event box to stop confictions in code. One example of this is in one of my other threads.

          The problem was the EXACT same when it was in the two events. I have also noticed that when I use the message box to disable the field the Tick is still visible in the box...I don't quite understand what's happening as the code looks and works okay other than this...

          /Sandy

          Comment

          • greeni91
            New Member
            • Nov 2009
            • 61

            #6
            I managed to fix the code to work the way I want... I was changing things in the Form_Current() section and forgot to update the changes in the AfterUpdate() section. Once these were changed the code worked no problems.... Thanks very much for all your help Missinglinq...

            The code is now as follows for Form_Current():

            Code:
            If Me.ONTick = True Then
              Me.OperatorName.Enabled = False
             Else
              Me.OperatorName.Enabled = True
             End If
              
            Dim PWord As String
              
            Dim FixedPassword As String
            FixedPassword = "Unlock"
              
             If ONTick.Value = -1 Then
              PWord = InputBox("Enter Password to Unlock Operator Name Field", "Enter Password")
                If PWord = FixedPassword Then
                 Me.OperatorName.Enabled = True
            Else
                 MsgBox "Password Incorrect!"
                 Me.ONTick.Value = 0
                 Me.OperatorName.Enabled = False
               End If
             End If
            and the code in the AfterUpdate field is:

            Code:
            Private Sub ONTick_AfterUpdate()
             
             If Me.ONTick = True Then
              Me.OperatorName.Enabled = True
             Else
              Me.OperatorName.Enabled = False
             End If
             
            Dim PWord As String
              
            Dim FixedPassword As String
            FixedPassword = "Unlock"
              
             If ONTick.OldValue = -1 Then
              PWord = InputBox("Enter Password to Unlock Operator Name Field", "Enter Password")
                If PWord = FixedPassword Then
                 Me.OperatorName.Enabled = True
                 Me.ONTick = -1
                Else
                 MsgBox "Password Incorrect!"
                 Me.ONTick.Value = 0
                 Me.OperatorName.Enabled = False
               End If
             End If
             
            End Sub
            Again Thanks Very Much

            /Sandy

            Comment

            Working...