Link to home
Start Free TrialLog in
Avatar of Drizzt420
Drizzt420

asked on

Make The Selections Available In ComboBox2 Dependant On The Value Of ComboBox1

I have a series of combo boxes. I want to use VBA to change the values available in the second combo box, based on what was chosen in the first one.

I think the following code, (even though its non-working), shows what I am wanting to do:

Private Sub CboBox1_AfterUpdate()

If Me.CboBox1 = "Choice1" Then
Me.CboBox2.RowSource = "Result1";"Result2";"Result3"
ElseIf Me.CboBox1 = "Choice2" Then
Me.CboBox2.RowSource = "Result4";"Result5";"Result6"

End Sub

I have seen examples of combo boxes that do something similiar to what I am wanting to do, but they all used select statements - Is there a way to control the options available in a combo box purely with VBA?
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Select Case Me.CboBox1
    Case "Choice1"
        Me.CboBox2.RowSource = "Result1;Result2;Result3"
    Case "Choice2"
        Me.CboBox2.RowSource = "Result4;Result5;Result6"
End Select
I would advise against hard coding this.  Instead, put those option combinations in a table and use queries as the source for your combo boxes.

The second combo would have a source like

Select field2 from yournewtable
Where field1 = forms!yourformname.combo1