dependent combo box

J

Jenny

I have 2 combo boxes on a form, cbostate and cbocounty. I want the cbocounty
combo to list only counties in the state chosen in the first combo box. Here
is what I have, but the cbocounty combo box doesn't update and display any
counties.
I have a table of unique State and county combinations called tblCounty-ST.
The row source for cbostate is...
SELECT DISTINCT [tblCounty-ST].ST FROM [tblCounty-ST] ORDER BY
[tblCounty-ST].ST;
The after update event code is...
rivate Sub cbostate_AfterUpdate()
On Error Resume Next
cbocounty.RowSource = "Select tblCounty-ST.Cty " & _
"FROM tblCounty-ST " & _
"WHERE tblCounty-ST.ST = '" & cbostate.Value & "' " & _
"ORDER BY tblCountry-ST.Cty;"
End Sub
my row source for cbocounty is blank.

thanks in advance
 
J

jahoobob via AccessMonster.com

Try this site:
http://www.pacificdb.com.au/MVP/Code/ComboRS.htm

I have 2 combo boxes on a form, cbostate and cbocounty. I want the cbocounty
combo to list only counties in the state chosen in the first combo box. Here
is what I have, but the cbocounty combo box doesn't update and display any
counties.
I have a table of unique State and county combinations called tblCounty-ST.
The row source for cbostate is...
SELECT DISTINCT [tblCounty-ST].ST FROM [tblCounty-ST] ORDER BY
[tblCounty-ST].ST;
The after update event code is...
rivate Sub cbostate_AfterUpdate()
On Error Resume Next
cbocounty.RowSource = "Select tblCounty-ST.Cty " & _
"FROM tblCounty-ST " & _
"WHERE tblCounty-ST.ST = '" & cbostate.Value & "' " & _
"ORDER BY tblCountry-ST.Cty;"
End Sub
my row source for cbocounty is blank.

thanks in advance
 
J

Jenny

I tried using the code from the website, but I'm still not getting any data
in my 2nd combo box after selecting from my first combo box. Not sure what
I'm doing wrong.

jahoobob via AccessMonster.com said:
Try this site:
http://www.pacificdb.com.au/MVP/Code/ComboRS.htm

I have 2 combo boxes on a form, cbostate and cbocounty. I want the cbocounty
combo to list only counties in the state chosen in the first combo box. Here
is what I have, but the cbocounty combo box doesn't update and display any
counties.
I have a table of unique State and county combinations called tblCounty-ST.
The row source for cbostate is...
SELECT DISTINCT [tblCounty-ST].ST FROM [tblCounty-ST] ORDER BY
[tblCounty-ST].ST;
The after update event code is...
rivate Sub cbostate_AfterUpdate()
On Error Resume Next
cbocounty.RowSource = "Select tblCounty-ST.Cty " & _
"FROM tblCounty-ST " & _
"WHERE tblCounty-ST.ST = '" & cbostate.Value & "' " & _
"ORDER BY tblCountry-ST.Cty;"
End Sub
my row source for cbocounty is blank.

thanks in advance
 
D

Douglas J. Steele

Unfortunately, none of us can offer any suggestions without knowing what
you've tried so far.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Jenny said:
I tried using the code from the website, but I'm still not getting any data
in my 2nd combo box after selecting from my first combo box. Not sure
what
I'm doing wrong.

jahoobob via AccessMonster.com said:
Try this site:
http://www.pacificdb.com.au/MVP/Code/ComboRS.htm

I have 2 combo boxes on a form, cbostate and cbocounty. I want the
cbocounty
combo to list only counties in the state chosen in the first combo box.
Here
is what I have, but the cbocounty combo box doesn't update and display
any
counties.
I have a table of unique State and county combinations called
tblCounty-ST.
The row source for cbostate is...
SELECT DISTINCT [tblCounty-ST].ST FROM [tblCounty-ST] ORDER BY
[tblCounty-ST].ST;
The after update event code is...
rivate Sub cbostate_AfterUpdate()
On Error Resume Next
cbocounty.RowSource = "Select tblCounty-ST.Cty " & _
"FROM tblCounty-ST " & _
"WHERE tblCounty-ST.ST = '" & cbostate.Value & "' " & _
"ORDER BY tblCountry-ST.Cty;"
End Sub
my row source for cbocounty is blank.

thanks in advance
 
J

Jana

Unfortunately, none of us can offer any suggestions without knowing what
you've tried so far.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)




I tried using the code from the website, but I'm still not getting any data
in my 2nd combo box after selecting from my first combo box. Not sure
what
I'm doing wrong.
Try this site:
http://www.pacificdb.com.au/MVP/Code/ComboRS.htm
Jenny wrote:
I have 2 combo boxes on a form, cbostate and cbocounty. I want the
cbocounty
combo to list only counties in the state chosen in the first combo box.
Here
is what I have, but the cbocounty combo box doesn't update and display
any
counties.
I have a table of unique State and county combinations called
tblCounty-ST.
The row source for cbostate is...
SELECT DISTINCT [tblCounty-ST].ST FROM [tblCounty-ST] ORDER BY
[tblCounty-ST].ST;
The after update event code is...
rivate Sub cbostate_AfterUpdate()
On Error Resume Next
cbocounty.RowSource = "Select tblCounty-ST.Cty " & _
"FROM tblCounty-ST " & _
"WHERE tblCounty-ST.ST = '" & cbostate.Value & "' " & _
"ORDER BY tblCountry-ST.Cty;"
End Sub
my row source for cbocounty is blank.
thanks in advance

- Show quoted text -

Jenny:

Try putting square brackets around your table name in your SQL:
cbocounty.RowSource = "Select [tblCounty-ST].Cty " & _
"FROM [tblCounty-ST] " & _
"WHERE [tblCounty-ST].ST = '" & cbostate.Value & "' " & _
"ORDER BY [tblCountry-ST].Cty;"

HTH,
Jana
 

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

Top