Lock Fields on Form

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
 
C

Carl Rapson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top