Solved

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

Posted on 2013-01-19
3
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 48

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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