Locking fields on Form using a check box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MellieDawn
    New Member
    • Sep 2008
    • 4

    Locking fields on Form using a check box

    Hello

    I want to lock my form or record from editing after the user clicks a checkbox to prevent any changes to that record. I do not have any subforms. The checkbox is named Completed. Any advice? And I am using access 2003.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Place the following code in the AfterUpdate() Event of the Completed Check Box:
    Code:
    Private Sub Completed_AfterUpdate()
    On Error Resume Next
    Dim ctl As Control
    
    For Each ctl In Me.Controls
      'If Control Name is NOT "Completed" and it is Checked, Lock all other
      'Controls. If it is not checked Unlock them
      If ctl.Name <> "Completed" Then
        ctl.Locked = Me![Completed]     'Evaluates to True/False
      End If
    Next
    
    End Sub

    Comment

    • MellieDawn
      New Member
      • Sep 2008
      • 4

      #3
      I used the code as shown below and it did not produce any results. However it didnt give me an error which is the first time that hasnt happened since I attempted to write the code myself.


      Private Sub Completed_After Update()
      On Error Resume Next
      Dim ctl As Control

      For Each ctl In Me.Controls
      'If Control Name is NOT "Completed" and it is Checked, Lock all other
      'Controls. If it is not checked Unlock them
      If ctl.Name <> "Completed" Then
      ctl.Locked = Me![Completed] 'Evaluates to True/False
      End If
      Next

      End Sub

      Comment

      • MellieDawn
        New Member
        • Sep 2008
        • 4

        #4
        I used the code as shown below and it did not produce any results. However it didnt give me an error which is the first time that hasnt happened since I attempted to write the code myself.


        Private Sub Completed_After Update()
        On Error Resume Next
        Dim ctl As Control

        For Each ctl In Me.Controls
        'If Control Name is NOT "Completed" and it is Checked, Lock all other
        'Controls. If it is not checked Unlock them
        If ctl.Name <> "Completed" Then
        ctl.Locked = Me![Completed] 'Evaluates to True/False
        End If
        Next

        End Sub

        Originally posted by ADezii
        Place the following code in the AfterUpdate() Event of the Completed Check Box:
        Code:
        Private Sub Completed_AfterUpdate()
        On Error Resume Next
        Dim ctl As Control
        
        For Each ctl In Me.Controls
          'If Control Name is NOT "Completed" and it is Checked, Lock all other
          'Controls. If it is not checked Unlock them
          If ctl.Name <> "Completed" Then
            ctl.Locked = Me![Completed]     'Evaluates to True/False
          End If
        Next
        
        End Sub

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by MellieDawn
          I used the code as shown below and it did not produce any results. However it didnt give me an error which is the first time that hasnt happened since I attempted to write the code myself.


          Private Sub Completed_After Update()
          On Error Resume Next
          Dim ctl As Control

          For Each ctl In Me.Controls
          'If Control Name is NOT "Completed" and it is Checked, Lock all other
          'Controls. If it is not checked Unlock them
          If ctl.Name <> "Completed" Then
          ctl.Locked = Me![Completed] 'Evaluates to True/False
          End If
          Next

          End Sub
          Did you click on the Check Box Completed, then try to Edit a Field?

          Comment

          • MellieDawn
            New Member
            • Sep 2008
            • 4

            #6
            Originally posted by ADezii
            Did you click on the Check Box Completed, then try to Edit a Field?
            Yes, it works initially. I check completed. I try to enter another information in another field and it will not allow edits.

            However, if I close the form and reopen it it allows me to edit the record even with completed checked.

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              For the formatting to be persisted when moving record-to-record or when closing then re-opening the form, you have to use the Form_Current event to check whether the checkbox is ticked and then lock everything or unlock everything accordingly.

              Welcome to Bytes!

              Linq ;0>

              Comment

              Working...