Query Filter Based on Mainform

  • Thread starter Thread starter Jen Preston via AccessMonster.com
  • Start date Start date
J

Jen Preston via AccessMonster.com

I have a main form with data filtered based on the company name pick from
the combo box. I have a button on this form to query this dataset of
records. But my query will not filter.

When I click on the button, I would like the query to bring up records
based on the dropdown company name. (to query all records with that company
name) Here's my code:

Private Sub QueryMissing_Click()
Dim sFilter As String
sFilter = [CompanyName]

CompanyName = sFilter
DoCmd.OpenQuery "qryMissingData"

End Sub
 
Does the qryMissingData query have a criterion expression that looks to the
combo box on the form for the filtering value? Post the SQL of the query so
we can assist you with this. Also tell us the names of the form and the
combo box.
 
Hi Ken,
My combo box name is "combo170" and the form is "frmEdit". Here is my sql
for the query "qryMissingData"

SELECT tblJOProfile.CompanyName, tblJOProfile.Companyid,
tblJOProfile.CompanyNum, tblJOProfile.Admin, tblJOProfile.DateUpdated,
tblJOProfile.Complete, tblJOProfile.MJ, tblJOProfile.CandidateL,
tblJOProfile.SSN,
FROM tblJOProfile;

Thanks,
 
To make the setup work as you wish, change the query's SQL statement to
this:

SELECT tblJOProfile.CompanyName, tblJOProfile.Companyid,
tblJOProfile.CompanyNum, tblJOProfile.Admin, tblJOProfile.DateUpdated,
tblJOProfile.Complete, tblJOProfile.MJ, tblJOProfile.CandidateL,
tblJOProfile.SSN,
FROM tblJOProfile
WHERE tblJOProfile.CompanyName = Forms!frmEdit!combo170;
 
Back
Top