
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