Locked Certain Fields On Load

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
 
P

peter walker

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
 
G

Guest

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
 
G

Guest

I just found my subform control doesn't work with the lock code. Can subform
controls be locked?
ck
 
P

peter walker

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
 

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

Similar Threads

Locking Fields 18
Form/Subform Problems 3
Locking controls at runtime 1
Form when populate execute code 2
calling an unbound combobox? 4
Problem with screen.activeform 3
Can't Delete last record 9
Locking a field 6

Top