Disabling fields based on Yes/No selection

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

Guest

i have a Yes/No button on one page of my tab control and when I select one
option, I want it to grey out certain fields on that page (disable them as
well). and when I select the other option, I want it to grey out (disable)
other certain fields on the same tab control page. Does anyone know how/if I
can do this? Thanks!
 
One note about my original post is that this is actually 2 radio buttons, and
when I select a certain one, I want certain options to be disabled (greyed
out) and vise versa.
 
StaceyJ said:
i have a Yes/No button on one page of my tab control and when I select one
option, I want it to grey out certain fields on that page (disable them as
well). and when I select the other option, I want it to grey out
(disable)
other certain fields on the same tab control page. Does anyone know
how/if I
can do this? Thanks!

Stacey,

If you are using a checkbox you can check its state and enable/disable other
controls based on that. Please the following code on the checkbox OnClick
event, and rename the control names to yours. Ex.

Private Sub MyCheckBox_OnClick()
Dim Status as boolean

'checkbox values are -1 for True
' 0 for False
' Null for Gray or Unselected.

If IsNull(MyCheckBox.Value) then
Status = False
Else
if MyCheckBox.Value = -1 then
Status = True
Else
Status = False
End If
End If

'Disable/Enable other controls based on the status variable

MyOtherControl1.Enable = Not Status

End Sub

Hope that helps
 
StaceyJ said:
One note about my original post is that this is actually 2 radio buttons,
and
when I select a certain one, I want certain options to be disabled (greyed
out) and vise versa.

Stacey,

Thanks for clarifying. If the option controls are radio buttons, then adapt
the following to my previous post. Basically you will need to use the
AfterUpdate event of the frame control containing the 2 radio buttons.

Private Sub Frame11_AfterUpdate()
Dim Status as boolean

If IsNull(Frame1.value) then
Status = False
Else
If Frame1.Value = 1 then
Status = True
Else
'this is value 2
Status = False
End If
End If

MyOtherControls1.enable = Not Status

End Sub
 
Hi Randy,

Thanks for your response. I am having a few problems running the code,
though. I changed the frame1.value references to read host_type.value (the
name of my Option Group control frame. But I'm not sure how to work with the
"MyOtherControls1.enable = Not Status" portion. Do I just rename the
"MyOtherControls1" part to the name of one of my controls, and create a
running list that might read something like "name.enable=Not Status" or
something like that? I tried it, and the debugger started up and took me to
the Private Sub line of that After Update event.

I can't seem to quite discern what is wrong.

I also am wondering how I will convert your code so that when value 1 is
selected, I only enable certain fields, and when value 2 is selected I enable
different fields.

I really appreciate your guidance.

Happy New Year!

--Stacey
 
Maybe I need to make one more distinguishing comment that this is not JUST
radio button, but that it's an option group. Is that what you assumed?
 
StaceyJ said:
Hi Randy,

Thanks for your response. I am having a few problems running the code,
though. I changed the frame1.value references to read host_type.value
(the
name of my Option Group control frame. But I'm not sure how to work with
the
"MyOtherControls1.enable = Not Status" portion. Do I just rename the
"MyOtherControls1" part to the name of one of my controls, and create a
running list that might read something like "name.enable=Not Status" or
something like that? I tried it, and the debugger started up and took me
to
the Private Sub line of that After Update event.

I can't seem to quite discern what is wrong.

I also am wondering how I will convert your code so that when value 1 is
selected, I only enable certain fields, and when value 2 is selected I
enable
different fields.

I really appreciate your guidance.

Happy New Year!

--Stacey

Stacey,

In the snippet code "MyOtherControls1" refers to any control you want to
enable/disable based on the current value of your Option Group/Frame. You
could replace that and use the name of the real control on your form. For
instance, if you want to disable/enable an OK button then it will be
something like:

cmdMyOKbutton1.Enable = Not Status

....And if you have more controls you want to disable/enable, just keep
adding below

cmdMyOKbutton1.Enable = Not Status
cmdMyOKbutton2.Enable = Not Status
cmdMyOKbutton3.Enable = Not Status

Please note that there might be cases where you want to do the opposite for
a specific control. For example, the following code will always have
different alternate Status.

cmdMyOKbutton1.Enable = Not Status
cmdMyOKbutton2.Enable = Status
cmdMyOKbutton3.Enable = Not Status

When the second button is enabled the other two will be disabled, and when
they are enabled the second button will be disabled. Adapt the code to your
scenario.

So it will be something like this


Private Sub Frame1_AfterUpdate()
Dim Status as boolean

' Process the selected value of the frame and
' determine whether disable or enable the co-related controls

If IsNull(Frame1.value) then
Status = False
Else
If Frame1.Value = 1 then
Status = True
Else
'this is value 2
Status = False
End If
End If

' Disable/Enable the co-related controls based on
' the status variable

cmdMyCommandButton1.Enable = Not Status
cmdMyCommandButton2.Enable = Not Status
cmdMyCommandButton3.Enable = Not Status
txtMyTextBox1.Enable = Not Satus
txtMyTextBox2.Enable = Not Status

End Sub


Hope it helps
 
Back
Top