Consulting

Results 1 to 8 of 8

Thread: Userform - is it possible?

  1. #1

    Userform - is it possible?

    Is it possible to have certain textboxes available dependent on which option button is selected? Any help with the code would be appreciated

    e,g If optionbutton 1 is selected then textbox1 & 2 available (for input)
    If optbut 2 selected then txtbox 1 & 3 available
    If optbut 3 selected then txtbox 2 & 3 available

    thanks

    Jon

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub OptionButton1_Click()
    With Me

    .TextBox1.Visible = True
    .TextBox2.Visible = True
    .TextBox3.Visible = False
    End With
    End Sub

    Private Sub OptionButton2_Click()
    With Me

    .TextBox1.Visible = True
    .TextBox2.Visible = False
    .TextBox3.Visible = True
    End With
    End Sub

    Private Sub OptionButton3_Click()
    With Me

    .TextBox1.Visible = False
    .TextBox2.Visible = True
    .TextBox3.Visible = True
    End With
    End Sub

    Private Sub Userform_Activate()

    Me.OptionButton1.Value = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks XLD - works like a charm.

    Have another question on userforms - I think its possible - If I say had 3 optionbuttons on a user form - by hitting command button can I display a further userform dependent on which option button is active? Something like 'if optbut1 selected show userform2, if optbut2 selected show useform3 etc.

    thanks

  4. #4
    I would suggest that in the withme sections of each optionbox write an identifying integer or string to a variable ( i.e ident =1 or ident= opt1 where ident is the variable which is declared general in the userform) and then in the command button have a group of cascaded ifs so that depending on what options were selected it will change what form is being opened.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub CommandButton1_Click()

    If Me.OptionButton1 Then

    Userform2.Show
    ElseIf Me.OptionButton2 Then

    Userform3.Show
    Else

    Userform4.Show
    End If
    [/vba]

    BTW, you should use more meaningful names than OptionButton1, Userform2, etc.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    mmmh I'll have to think about it a bit - a little confused

    thanks anyway

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    By what?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Thanks again XLD - it is pretty logical when you think about it - problem is I am a fairly infrequent user of vba - just need a bit of help to get started (and I was never much good a logic!)

    thanks again

Posting Permissions

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