Cascading ComboBox

E

Evan

I have read all the posts and links on this. I've seen 2 ways to make Combo2
contingent on Combo1:

1. Add this sql code to Combo2 property's Row Source:
SELECT DISTINCTROW [Table7].[zip] FROM Table7 WHERE ((([Table7].[city]) Like
[forms]![frmSimple]![combo0]));

and add the code:
Private Sub Combo1_AfterUpdate()
Me!Combo2 = Null
Me!Combo2.Requery
End Sub

2. Add code in the AfterUpdate event of cbxCombo1 that assigns the proper
RowSource to cbxCombo2:

Private Sub cbxCombo1_AfterUpdate()
Dim strSQL As String
strSQL = "Select " & Me!cbxCombo1
strSQL = strSQL & " from Categories"
Me!cbxCombo2.RowSourceType = "Table/Query"
Me!cbxCombo2.RowSource = strSQL
End Sub

and add the code:
Private Sub Combo1_AfterUpdate()
Me!Combo2 = Null
Me!Combo2.Requery
End Sub

My question: is one better than the other?

Evan
 
J

Jeff Boyce

Uhmmm? "WHERE xxx Like yyy"?

If your first combobox (?[combo0]?) limits to a single record (and it
appears to be a single city), why would you want your second combobox to
include records where the city was "like" the first selection? Wouldn't you
want it to be exactly what was selected?

And your question about whether one approach is "better" than the other...

What criteria are you using to decide "better"? ?Easier for a programmer?
?Faster? ?More maintainable? ?whatever WE think means 'better'?!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top