Consulting

Results 1 to 5 of 5

Thread: Enable/Disable TextBox based on Option Selection

  1. #1
    VBAX Newbie
    Joined
    Jun 2010
    Posts
    2
    Location

    Enable/Disable TextBox based on Option Selection

    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.

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    [vba]Private Sub optPriority3_Click()
    txtCompTime.Enabled = True
    End Sub

    Private Sub UserForm_Initialize()
    txtCompTime.Enabled = False

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

    [vba]txtCompTime.Text = ""
    txtCompTime.Enabled = False[/vba]to clear out the field if they change their mind and select another option button.

    David


  3. #3
    VBAX Newbie
    Joined
    Jun 2010
    Posts
    2
    Location
    Thanks. Works great.

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •