Consulting

Results 1 to 4 of 4

Thread: Using Option button in userform

  1. #1

    Question Using Option button in userform

    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.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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

  3. #3
    What did you mean by "set the default for the textboxes .enabled property to False"
    I only added the code you gave me.

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    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.

Tags for this Thread

Posting Permissions

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