MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Option button / txtbox - Visible/enabled

Posted by tee on January 21, 2002 7:43 PM

Hi Everyone

How do I make a txtbox visible depending on the result of an option button.

I have 3 option buttons in a frame. I have a txtbox with a date in it. When option button 1 is true, I want the txtbox for the date to be visible = false or enabled = false.

I have tried this but it does not work.

Private Sub OptNoVIS_Click()
If OptNoVIS = True Then
txtVisDate.Visible = False
txtVisDate.Visible = True
End Sub

Many thanks again.

Posted by Damon Ostrander on January 21, 2002 11:43 PM

Hi Tee,

I believe the easiest way is to just do the following:

Private Sub OptNoVIS_Click()
txtVisDate.Visible = Not OptNoVIS.Value
End Sub

which just makes the boolean value of the Visible property of the textbox the opposite of the boolean value of the option button. Give it a try.


Posted by marc on January 22, 2002 11:46 AM

Tee- Looks like Damon gave you some concise code. Just to comment on your code, looks like you were just missing the enabled property for your option button.
OptNoVIS = True should read OptNoVIS.enabled = True
If you want the date to reappear should you choose another option button you'll need to code each button to make the textbox visible.

Private Sub OptionButton1_Click()
If OptionButton1.Enabled = True Then
TextBox1.Visible = False
End If
End Sub

Private Sub OptionButton2_Click()
If OptionButton2.Enabled = True Then
TextBox1.Visible = True
End If
End Sub

Private Sub OptionButton3_Click()
If OptionButton3.Enabled = True Then
TextBox1.Visible = True
End If
End Sub