Combo box controlling visibility

Discussion in 'Microsoft Excel Programming' started by chis, Nov 10, 2003.

  1. chis

    chis Guest

    I have a user form in VB that contains multiple
    comboboxes. I am looking to haave the first combobox
    control the Visible property of the other boxes. any
    help is appreciated
     
    chis, Nov 10, 2003
    #1
    1. Advertisements

  2. chis

    Tom Ogilvy Guest

    Private Sub combobox1_Click()
    dim cbox = MSForms.Combobox
    for each ctrl in Userform1.Controls
    if typeof ctrl is MsForms.Combobox then
    set cbox = ctrl
    if right(cbox.name,1) <> 1 then
    cbox.visible = False
    end if
    end if
    Next
    Controls("Combobox" & combobox1.Listindex + 2).Visible = True
    Me.Repaint
    End Sub

    would be a guess at what you want.

    --
    Regards,
    Tom Ogilvy


    chis <> wrote in message
    news:042101c3a729$de640360$...
    > I have a user form in VB that contains multiple
    > comboboxes. I am looking to haave the first combobox
    > control the Visible property of the other boxes. any
    > help is appreciated
     
    Tom Ogilvy, Nov 10, 2003
    #2
    1. Advertisements

  3. Hello again. Ithink I might have been a little vague with what I was
    looking for. I have combobox1 and it has a few variables. When the
    user selects variable 1 I would like combobox2 to become visible. If
    they choose variable 2 then combobox3 becomes visible and so on.
    I don't knw why I didn't put it that way the first time.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Chris LeBlanc, Nov 10, 2003
    #3
  4. chis

    Tom Ogilvy Guest

    That is what I assumed, that is what I gave you although I hide all but
    combobox1 first and then the appropriate combobox is made visible. It
    assumes comboboxes are named combobox1, combobox2, etc

    so if the select item is the first item, then listindex is zero and zero
    plus 2 is 2, so combobox & (listindex + 2) is made visible (combobox2).



    --
    Regards,
    Tom Ogilvy

    "Chris LeBlanc" <> wrote in message
    news:...
    > Hello again. Ithink I might have been a little vague with what I was
    > looking for. I have combobox1 and it has a few variables. When the
    > user selects variable 1 I would like combobox2 to become visible. If
    > they choose variable 2 then combobox3 becomes visible and so on.
    > I don't knw why I didn't put it that way the first time.
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Tom Ogilvy, Nov 10, 2003
    #4
  5. chis

    Chris Guest

    Hi there again. I pasted the code into the form's codes and I receive
    an error. The error is that "dim cbox = MSForms.ComboBox" is a compile
    error:Syntax error.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Chris, Nov 11, 2003
    #5
  6. chis

    Tom Ogilvy Guest

    dim cbox = MSForms.Combobox
    should be
    dim cbox as MSForms.Combobox

    while I apologize for the typo, should you really be attempting this?

    Anyway, I copied this form a working USERFORM

    Private Sub combobox1_Click()
    Dim cbox As MSForms.ComboBox
    For Each ctrl In UserForm1.Controls
    If TypeOf ctrl Is MSForms.ComboBox Then
    Set cbox = ctrl
    If Right(cbox.Name, 1) <> 1 Then
    cbox.Visible = False
    End If
    End If
    Next
    Controls("Combobox" & ComboBox1.ListIndex + 2).Visible = True
    Me.Repaint
    End Sub

    Private Sub UserForm_Initialize()
    Dim cbox As MSForms.ComboBox
    For i = 1 To 5
    For j = 1 To 4
    Controls("ComboBox" & i).AddItem "Item " & j
    Next
    Next

    For Each ctrl In UserForm1.Controls
    If TypeOf ctrl Is MSForms.ComboBox Then
    Set cbox = ctrl
    If Right(cbox.Name, 1) <> 1 Then
    cbox.Visible = False
    End If
    End If
    Next

    End Sub

    Tested in xl97, SR2

    --
    Regards,
    Tom Ogilvy

    Chris <> wrote in message
    news:...
    > Hi there again. I pasted the code into the form's codes and I receive
    > an error. The error is that "dim cbox = MSForms.ComboBox" is a compile
    > error:Syntax error.
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Tom Ogilvy, Nov 11, 2003
    #6
  7. chis

    Chris Guest

    It is probably over my head but I have been trying to figure a quick way
    to do what has taken an entire page of activex controls. Thanks for all
    the help.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Chris, Nov 14, 2003
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Combo Box - Hide Combo Box w/Check Box

    Guest, Dec 1, 2004, in forum: Microsoft Excel Programming
    Replies:
    5
    Views:
    576
    Dave Peterson
    Dec 3, 2004
  2. Guest

    create a second combo box from a first combo box

    Guest, Feb 14, 2005, in forum: Microsoft Excel Programming
    Replies:
    2
    Views:
    312
    Guest
    Feb 14, 2005
  3. Guest

    Combo box values based on other combo box value

    Guest, Apr 5, 2005, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    451
    Ron de Bruin
    Apr 5, 2005
  4. controlling a pivot table using a combo box

    , Oct 5, 2005, in forum: Microsoft Excel Programming
    Replies:
    4
    Views:
    1,385
    Guest
    Oct 13, 2005
  5. mtm4300 via OfficeKB.com

    Combo Box to Combo Box Selections

    mtm4300 via OfficeKB.com, Feb 10, 2006, in forum: Microsoft Excel Programming
    Replies:
    12
    Views:
    417
    Tom Ogilvy
    Feb 10, 2006
Loading...

Share This Page