Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Cascading ComboBox

Geek News

Cascading ComboBox
Evan 12/30/2008 5:30:04 PM
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

Re: Cascading ComboBox
"Jeff Boyce" <nonsense[ at ]nonsense.com> 12/30/2008 5:51:31 PM
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

"Evan" <Evan[ at ]discussions.microsoft.com> wrote in message
news:032CF161-CD49-4FEF-BB7F-A68DF079AAC4[ at ]microsoft.com...
[Quoted Text]
>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
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net