Log in

View Full Version : Enable/Disable TextBox based on Option Selection



mbutler
06-22-2010, 01:51 PM
I have a UserForm with 3 option buttons. Below the option buttons I have a text box that is only necessary when the third option button is selected. I need to know how to make the text box dimmed and disabled unless the third option button is selected. The third option button is called "optpriority3" and the text box is called "txtcomptime". Any help would be greatly appreciated.

Tinbendr
06-22-2010, 07:23 PM
Private Sub optPriority3_Click()
txtCompTime.Enabled = True
End Sub

Private Sub UserForm_Initialize()
txtCompTime.Enabled = False

End Sub
In each of the other option button Click events, you'll need to add

txtCompTime.Text = ""
txtCompTime.Enabled = Falseto clear out the field if they change their mind and select another option button.

mbutler
06-23-2010, 09:22 AM
Thanks. Works great.

fumei
06-23-2010, 09:34 AM
Me, I would make the textbox either visible and enabled, or not visible. demo attached. Click "Show Me" on the top toolbar. Depending on whether Priority 3 is true, or not, the userform dimensions change, thus making the textbox either visible, or not. The commandbutton just does an Unload Me.

fumei
06-23-2010, 09:34 AM
Me, I would make the textbox either visible and enabled, or not visible. demo attached. Click "Show Me" on the top toolbar. Depending on whether Priority 3 is true, or not, the userform dimensions change, thus making the textbox either visible, or not. The commandbutton just does an Unload Me.