Locked Certain Fields On Load

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

Guest

Someone suggested this code to lock all fields when a form loads except
certain fields. I was trying to exclude an option group from being locked but
it doesn't seem to work with option group. The code:

Dim c as control
On error resume next
For each c in Me.Controls
If c.Name <> "OptionGroupName" Then
c.locked = true
End If
Next

Is the option group control different from the other types of controls?
Thanks.
ck
 
You are locking your option controls.
The option group or frame is being left unlocked but the code is then
locking the radio buttons, check boxes or toggle buttons.

Private Sub Command6_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
If c.Name <> "Frame0" And c.Parent.Name <> "Frame0" Then
c.Locked = True
Debug.Print c.Name, c.Parent.Name
End If
Next
End Sub

You should investigate the tag property as a status flag also.
peter walker
 
Thanks Peter, it worked like you said.
ck

peter walker said:
You are locking your option controls.
The option group or frame is being left unlocked but the code is then
locking the radio buttons, check boxes or toggle buttons.

Private Sub Command6_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
If c.Name <> "Frame0" And c.Parent.Name <> "Frame0" Then
c.Locked = True
Debug.Print c.Name, c.Parent.Name
End If
Next
End Sub

You should investigate the tag property as a status flag also.
peter walker
 
I just found my subform control doesn't work with the lock code. Can subform
controls be locked?
ck
 
The subform control is lockable and should lock using the same code. It
least text boxes etc on the for should be locked. Works here.
Failing that you can also repeat the code for the control collection on the
Me.MySubform.Form.Controls...

peter walker
 
Back
Top