Solved

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

Posted on 2013-01-19
3
287 Views
Last Modified: 2013-01-19
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?
0
Comment
Question by:Drizzt420
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38796378
Set the rowsource type to value list


Me.combo.rowsourcetype = "value list"
Me.combo.rowsource = "'apples', 'oranges','bananas'"
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38796388
Select Case Me.CboBox1
    Case "Choice1"
        Me.CboBox2.RowSource = "Result1;Result2;Result3"
    Case "Choice2"
        Me.CboBox2.RowSource = "Result4;Result5;Result6"
End Select
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 38797387
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
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This collection of functions covers all the normal rounding methods of just about any numeric value.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now