Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Unanswered: Lock Unlock Field

    I am trying to be able to lock and unlock a field using a option group. Here is my code.This is being executed when the user clicks on an option.Default is 2, unlocked. Code does not work ?

    Private Sub Frame93_Click()

    If Option96 = 1 Then ' Lock the field GirlID
    GirlID.Enabled = False
    End If
    If Option98 = 2 Then ' Unlock the field GirlID
    GirlID.Enabled = True
    End If
    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Private Sub Frame93_Click()
    
        If Me.Frame93.Value = 1 Then ' Lock the field GirlID
            Me.GirlID.Enabled = False
        ElseIf Me.Frame93.Value = 2 Then ' Unlock the field GirlID
            Me.GirlID.Enabled = True
        End If
    
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Nov 2011
    Posts
    413
    Problem with that is that it locks all of the GirlID field records . I just want to be able to lock the individual record as needed.

  4. #4
    Join Date
    Nov 2011
    Posts
    413
    Also the code only works while the form is open, it does not save the lock or unlock record in it's locked or unlocked state. Here is my new code which locks and unlocks 3 fields. If I close the form then all records are not locked even though I locked them using the code. Also using the locked when I try to create a new record, well the fields are locked of course,,,Problem !!!


    If Me.Frame102.Value = 1 Then ' Lock the field GirlID
    Me.GirlID.Enabled = False

    ElseIf Me.Frame102.Value = 2 Then ' Unlock the field GirlID
    Me.GirlID.Enabled = True

    End If
    If Me.Frame102.Value = 1 Then ' Lock the field Girl
    Me.Girl.Enabled = False

    ElseIf Me.Frame102.Value = 2 Then ' Unlock the field Girl
    Me.Girl.Enabled = True

    End If
    If Me.Frame102.Value = 1 Then ' Lock the field Age
    Me.Age.Enabled = False

    ElseIf Me.Frame102.Value = 2 Then ' Unlock the field Age
    Me.Age.Enabled = True

    End If

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by Burrina View Post
    Problem with that is that it locks all of the GirlID field records . I just want to be able to lock the individual record as needed.
    No it does not. It just enables/disables a Control on the current form. You seems to be confusing a bound control with the data it displays.
    Have a nice day!

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ut it will do that with a form using continuous forms
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    On a Continuous View or Datasheet View Form, you need to use the Locked Property, which doesn't change the physical appearance of the Control, but prevents it from having data entered via the keyboard. And, to keep the Locking/Unlocking appropriate to the Current Record, the code also needs to be in the Form_Current event, as well as in the AfterUpdate event of the Option Group.

    Code:
    Private Sub Frame102_AfterUpdate()
    
    If Me.Frame102.Value = 1 Then ' Lock the fields GirlID, Girl and Age
     
     Me.GirlID.Locked = True
     Me.Girl.Locked = True
     Me.Age.Locked = True
    
    Else ' Unlock the fields GirlID, Girl and Age
     
     Me.GirlID.Locked = False
     Me.Girl.Locked = False
     Me.Age.Locked = False
    
    End If
    
    End Sub
    
    Private Sub Form_Current()
    
    If Me.Frame102.Value = 1 Then ' Lock the fields GirlID, Girl and Age
     
     Me.GirlID.Locked = True
     Me.Girl.Locked = True
     Me.Age.Locked = True
    
    Else ' Unlock the fields GirlID, Girl and Age
     
     Me.GirlID.Locked = False
     Me.Girl.Locked = False
     Me.Age.Locked = False
    
    End If
    
    End Sub


    Linq ;0)>
    Last edited by Missinglinq; 08-07-12 at 09:43.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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