Access 2007 - Filter Combo Box options

I've got a form that is bound to a source that basically represents one record at a time with primary key being ProjectID.  Inside this form I have a combo box that allows me to select different projects.  I've got code written that automatically will update the record the form is bound to based on the selection of the projectID combo box.

Also in this form I have a sub form that is a continuous form and shows a listing of records.  One of the fields in this form is bound by a combo box having a row source built with quite a few options.  I need this list of options to be filtered by the project that is selected in the parent form.  I have the Link Master Field and the Link Child Field both set to ProjectID, I'm just not sure how to utilize that projectID to impose a filter on the combo box in the sub form.

If I need to say anything else to provide further clarification just let me know.

Who is Participating?
Rey Obrero (Capricorn1)Commented:
Add the field ProjectID to the RowSource

SELECT tbContractProject.ContractID, tbContract.Name, tbContractProject.ProjectID FROM tbContract INNER JOIN tbContractProject ON tbContract.ContractID=tbContractProject.ContractID
Where tbContractProject.ProjectID =Forms!NameOfParentForm!ProjectID

set the column count of the combo box to 3
Rey Obrero (Capricorn1)Commented:
you just need to set the rowsource of the combo box with a criteria that points to the ProjectID,

what is the rowsource of the combo?

JosephEricDavisAuthor Commented:
SELECT tbContractProject.ContractID, tbContract.Name FROM tbContract INNER JOIN tbContractProject ON tbContract.ContractID=tbContractProject.ContractID;

tbContractProject has a field, ProjectID, which is what I need to filter on.  Filter by the parent form ProjectID.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JosephEricDavisAuthor Commented:
It doesn't seem to be working when I set it this way in the row source directly in the properties window like this.

I can do it in code like this however...

Form_ExpenditureLedger.ddlContractProjectID.RowSource = "SELECT tbContractProject.ContractID, tbContract.Name FROM tbContract INNER JOIN tbContractProject ON tbContract.ContractID=tbContractProject.ContractID WHERE tbContractProject.ProjectID = Forms!frmExpenditure!ProjectID"

But I would rather not have to do it that way if I can avoid it.
Rey Obrero (Capricorn1)Commented:
<It doesn't seem to be working> why,
did you select a project form the combo box in the main form?

in this line

Forms!frmExpenditure!ProjectID   < ProjectID is a Combo box.. if it is , change name to cboProjectID

in the afterUpdate of cboProjectID

private sub cboProjectID_afterupdate()


end sub
JosephEricDavisAuthor Commented:
Actually, ok that will work fine.

But the next related problem is that I have a second combo box in the same row as the one previously in question.  The options available in this second combo box need to be set based on the value selected in the first.

This is an interesting problem because if I try to do it like I've done with the other one above, in code, then it will reset the values for all the combo boxes on the form, not just for the row the user is working on.

I need to have some way where I can filter the values in this second combo box based on the values selected in the first combo box on a row by row basis.
Rey Obrero (Capricorn1)Commented:

please, one question per thread
JosephEricDavisAuthor Commented:
ok... sorry.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.