Query Filter Based on Mainform

  • Thread starter Jen Preston via AccessMonster.com
  • 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
 
K

Ken Snell [MVP]

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.
 
J

Jen Preston via AccessMonster.com

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,
 
K

Ken Snell [MVP]

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;
 

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