Code Snippets → Lock Select Controls

There are times where you might want to lock select controls so that you can still use something on the form. Setting the AllowEdits property to NO will lock all of the controls that could be edited, including (for example) a combo box which you might want to use to search for a record.

So, what I will usually do is to put a word in the TAG property of the controls that I am going to want to lock and unlock. The word might be lock or something similar. Also, I will also usually include the Enabled property so that you can’t click into the field as well. If you just want it locked but leave it enabled then you can copy the text that is in the control.

So, for example:

Dim ctl As Control
For Each ctl In Me.Controls
    With ctl
       If .ControlType = acTextBox Then
          .Enabled = False
          .Locked = True
       End If
    End With
Next