PDA

View Full Version : Using Option button in userform



harber95
07-21-2015, 08:42 PM
I made a userform that have two options to choose from.
Each option button have its own text box.
I want to make both textboxes to be inactive (grey color) until an option is chosen, then one of the textboxes will be active. And if I choose the other option, I want the formally active textbox to be inactive.

mikerickson
07-21-2015, 10:35 PM
Set the default for the Textboxes .Enabled property to False and put this code in the user form's code module.


Private Sub OptionButton1_Change()
TextBox1.Enabled = OptionButton1.Value
TextBox2.Enabled = OptionButton2.Value
End Sub

Private Sub OptionButton2_Change()
TextBox1.Enabled = OptionButton1.Value
TextBox2.Enabled = OptionButton2.Value
End Sub

harber95
07-21-2015, 11:30 PM
What did you mean by "set the default for the textboxes .enabled property to False"
I only added the code you gave me.

mikerickson
07-23-2015, 11:16 AM
When you make the userform and place the controls where you want, the Properties window (in the lower left of the VBEditor screen) will list, for each control, the properties that control will have when the UF is opened. If you set the .Enabled property to False for both of your textboxes, they will start of .Enabled = False.