Populate one Combo box based on the value from another combo box (1 Viewer)

gsrajan

Registered User.
Local time
Today, 12:49
Joined
Apr 22, 2014
Messages
227
Please let me know how to populate one combo box with the field from a table based on the value selected in another combo box. I have two combo boxes, one for States and another for counties ( which is a field in a table)

Please let me know how to populate the county combo box based on the State the user select from the dropdown.

I tried this, but does not work

Private Sub CboCounty_Change()
Dim Dbs As Database
Dim Rst As Recordset
Dim MyString As String

Set Dbs = CurrentDb()
MyString = "Select County from TblGeography where State='" & CboState & "'"
Set Rst= Dbs.OpenRecordset(MyString)
Me.CboCounty.RowSource = MyString
Me.CboCounty.Requery
End Sub

Thanks for your help.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:49
Joined
Oct 29, 2018
Messages
21,478
Hi. Try to look up "cascading combobox." I think maybe that's what you mean.
 

bastanu

AWF VIP
Local time
Today, 09:49
Joined
Apr 13, 2010
Messages
1,402
Set the row source of the cboCounty to Select County from TblGeography where State = Forms!frmYourForrm!CboState (in design view) and in the OnEnter event of the cboCounty put Me.CboCounty.Requery .

Cheers,
Vlad
 

gsrajan

Registered User.
Local time
Today, 12:49
Joined
Apr 22, 2014
Messages
227
Thank you very much. The code works. I will also look into Cascading combo box. Thanks you both for the replies.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:49
Joined
Oct 29, 2018
Messages
21,478
Thank you very much. The code works. I will also look into Cascading combo box. Thanks you both for the replies.
Good luck with your project.
 

Users who are viewing this thread

Top Bottom