Lock Fields on Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to lock all fields on a form when a user clicks "Lock" and mark the
field [locked]=1, If I use allow edits = false, then the
combo box in the form header, used for searching, is also locked.
Is there an easier way besided locking each field invididually?

THanks,
Nancy
 
Nancy said:
I want to lock all fields on a form when a user clicks "Lock" and mark the
field [locked]=1, If I use allow edits = false, then the
combo box in the form header, used for searching, is also locked.
Is there an easier way besided locking each field invididually?

THanks,
Nancy

Not really, no. The best way to do this is probably to loop through the
Controls collection of the form and lock each control individually, skipping
whichever ones you don't want to lock. Something like this:

Private Sub LockControls(blnLock as Boolean)
Dim ctl as Control
For Each ctl In Me.Controls
If ctl.Tag = "Lock" Then
' Can't "lock" command buttons, so use Enabled instead
If ctl.ControlType = acCommandButton Then
ctl.Enabled = Not blnLock
Else
ctl.Locked = blnLock
End If
End If
Next
End Sub

Put this code in your form's code module. For each control that you want to
lock, put the text "Lock" (without the quotes) in the Tag property. To
ensure that your combo box isn't locked, leave its Tag property empty. Then
call this sub with either True or False, depending on whether you want to
lock (True) or unlock (False) the controls.

Carl Rapson
 
Back
Top