Populate a combo box from another combo box selection 
Author Message
 Populate a combo box from another combo box selection

I have two combo boxes and i want the second combo box to fill up with
choses that can be abtained with the selection of the combo box 1. How might
i go about doing this.

Thanks for your time

Chas



Sat, 15 Feb 2003 03:00:00 GMT  
 Populate a combo box from another combo box selection
Charles,

You didn't say what the second combo box was going to fill up with.  (Did I
just end a sentence in TWO prepositions?  d8^)

Here is some code that manually fills Combo2 with appropriate choices based
on Combo1's selection:

Private Sub Form_Load()
    ' Load the ComboBoxes
    Combo1.Clear
    Combo2.Clear

    Combo1.AddItem "Fruits"
    Combo1.AddItem "Dairy"
    Combo1.AddItem "Vegatables"
End Sub

Private Sub Combo1_Click()
    ' Fill Combo2 with the appropriate choices based on Combo1
    Combo2.Clear

    Select Case Combo1.ListIndex
        Case 0      ' first item in the list -- fruits
            Combo2.AddItem "Cherries"
            Combo2.AddItem "Apples"
            Combo2.AddItem "Oranges"
            Combo2.AddItem "Bananas"
        Case 1      ' dairy
            Combo2.AddItem "Milk"
            Combo2.AddItem "Butter"
            Combo2.AddItem "Cheese"
            Combo2.AddItem "Yogurt"
        Case 2      ' vegatables
            Combo2.AddItem "Corn"
            Combo2.AddItem "Peas"
            Combo2.AddItem "Carrots"
            Combo2.AddItem "Beans"
        Case Else      ' no selection
            Beep
            MsgBox "Combo Box 2 will not be filled", , "  No selection"
    End Select

    ' test is need in case Combo2 didn't get filled
    If Combo2.ListCount > 0 Then Combo2.ListIndex = 0
End Sub

If you need database stuff, there was just a Q&A a couple of days ago on
that subject.

Best of luck,

Michael


Quote:
> I have two combo boxes and i want the second combo box to fill up with
> choses that can be abtained with the selection of the combo box 1. How
might
> i go about doing this.

> Thanks for your time

> Chas



Sat, 15 Feb 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Populating a combo box from another combo box

2. Limit subform combo box by selection in parent combo box

3. Combo box selection narrows next combo box choices

4. populate textbox from external file depending on combo box selection

5. Unable to populate text box from combo box

6. populate text box from combo box (same form)

7. Can't get Combo Box selection into Text Box

8. List Box & Combo Box selection notification

9. enter data in a combo box based on value from another combo box

10. Want Access combo box to filter rowsource of another combo box

11. selecting records for 2nd combo box dependant on first combo box

12. Help filling second combo box from fist combo box

 

 
Powered by phpBB® Forum Software