Disable other text boxes using option group

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

Guest

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.
 
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
 
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
 
thanks, will this also clear the value in the text box or do I need to and
more code?
 

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

Back
Top