Combox box filtered based on other combo box

B

Ben Pelech

Hello,

I have 2 combo boxes. One is a category, and the other is a subcategory.
category combobox is cmbotype
subcategory combobox is cmboreason

My goal is to have cmboreason be limited only to the reasons that pertain to
the cmbotype category.

I have 2 tables:

the category table is
ContactID
ContactType

the subcategory table is
ReasonID
ContactID
Reasons

The Contact ID in the subcategory matches the ContactID in the contact type.

This code was entered in the Afterupdate of the category combo box

Private Sub cmbotype_AfterUpdate()
Dim sReason_for_Contact As String

sNewReasonsforCallSource = "SELECT [tblNewReasonsforCall].[ReasonID],
[tblNewReasonsforCall].[ContactID], [tblNewReasonsforCall].[Reasons] " & _
"FROM tblNewReasonsforCall " & _
"WHERE [ContactID] = " & Me.cmbotype.Value
Me.cmboreason.RowSource = sReason_for_ContactSource
Me.cmboreason.Requery

End Sub

I got the above code from another article that I was trying to follow, but
when I select the main category, the subcategory is blank. So I am sure I am
just entering the code wrong.

Any help would be greatly appreciated.

Thanks
Ben
 

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