Disable other text boxes using option group

N

Nick

I am using an option groups to turn certain textboxes off in a sub form. If
I use say option 2 how can I turn off the textbox named opportunities and
hrOffered.
 
K

Klatuu

If there are more than two options in your option group, use a Select Case
statement and put the code in the case where you want it to execute. To use
your example:

Select Case Me.OptionGroupControl
Case 1
'Do Stuff For Option Value 1
Case 2
Me.opportunities.Enabled = False
Me.hrOffered.Enabled = False
Case 3
'Do Stuff For Option 3
End Select
 
M

Marshall Barton

Nick said:
I am using an option groups to turn certain textboxes off in a sub form. If
I use say option 2 how can I turn off the textbox named opportunities and
hrOffered.


A general approach (might not be worth the effort for just
two text boxes) is to set the Tag property of the controls
you want to manipulate to something such as "OnOff". This
way, you can loop through the controls collection and set
the property (or properties) without knowing each control's
name or having duplicated code for each control.

Create a Sub procedure in a standard module:

Public Sub SetProps(frm As Form, switch As Boolean)
Dim ctl As Control
On Error Resume Next ' incase control does not have prop
For each ctl In frm.Controls
If ctl.Tag = "OnOff" Then
ctl.Locked = switch ' or Enabled, Visible, etc
End If
Next ctl
End Sub

Then any form can manipulate a set of controls in any open
form with code like:

SetProps Forms!nameofform, False ' or True

For a main form to do this for one of its subforms:

SetProps Me.subformcontrol.Form, False
 
Top