Cascading Combo boxes in form

hardrock

Registered User.
Local time
Today, 14:25
Joined
Apr 5, 2007
Messages
166
Hi all, I wish to use vba to complete 2 combobox selections, rather than use a query. so far i have

Combo1 = AAA
BBB

Combo2 = CCC
DDD
EEE
FFF

So if i choose AAA in combo1 then combo2 gives me the chioce of CCC or DDD
and if i choose BBB in combo1 then combo2 gives me the choice of EEE and FFF

Heres my code, but i need it to remove the items i dont need in combo2.
How do i quickly fix that in the code below? thanks

***********************
Private Sub Form_Load()
cboBox1.AddItem "AAA"
cboBox1.AddItem "BBB"



Private Sub cboBox1_AfterUpdate()

If cboBox1.Value = "AAA" Then
cbobox2.AddItem "CCC"
cbobox2.AddItem " DDD"
ElseIf cboBox1.Value = "BBB" Then
cbobox2.AddItem "EEE"
cbobox2.AddItem "FFF"
End If
End Sub
 
Dont know why you would ever do this but mine is not to question. Queries deal with this much more efficiently, and with little code.

If cboBox1.Value = "AAA" Then
cbobox2.RowSource ="CCC"; " DDD"
ElseIf cboBox1.Value = "BBB" Then
cbobox2.RowSource = "EEE";"FFF"
End If

You will need to set the the Row Source Type to Value List
 
hello

Thanks, but im getting a syntax error with the above code in the rowsource. it dont like ;
?
 
Opps, the code should have gone....

If Me.cboBox1 = "AAA" Then
Me.cbobox2.RowSource ="CCC;DDD"
ElseIf Me.cboBox1 = "BBB" Then
Me.cbobox2.RowSource = "EEE;FFF"
End If

Dave
 

Attachments

re:

Yes that works dave, Thankyou. But as soon as i enter cboxbox1, i want to clear the current value showing in cbobox2?
 
Use the Got Focus or On Enter event of Combo1:

Me.combo2 = ""

Dave
 
additem

Just playing around with Access 2000, i notice the additem and removeitem functions are not supported?? it works only with 2003 upwards.. what is the workaround in older versions of Access please?
 

Users who are viewing this thread

Back
Top Bottom