applying a filter to a query

H

happywitchie

I have a combo box on a form and when an item is selected, I want a query to
be returned with the results filtered to the selected item.

For example, when "Project2001" is selected, the returned query should only
display the data relating to Project2001.

The code I have is:
[Parent Project]=[Forms]![Reports and Queries Form]![cmbProject]

[Parent Project] is the field in the query that I need to set the filter
criteria to.

However, the above code does not work - it says that it doesn't recognise
"[Forms]![Reports and Queries Form]![cmbProject]"

Can anyone suggest what I have done wrong? Also, where do I put this code?
At the moment I have it in a macro as follows:
OpenQuery: qryProject
ApplyFilter: [Parent Project]=[Forms]![Reports and Queries
Form]![cmbProject]

Thanks
hw
 
G

Guest

Hi happywitchie,

This is what needs to happen when query by a form.
1) The has to be opened and the criteria is filled in. In your case, your
combo box with "Project2001" selected.
2) Need to open the query with the query criteria use the form's value.
Your query should look like "select * from table where criteria =
[forms]![myopenedform]![combo box];"
3) If you want macro to do the query, you can called the macro from your
form. That can be done as part of the afterupdate or a button on the form.

Hope this helps.
 
H

happywitchie

Thank you! I got it working. Much appreciated!


JL said:
Hi happywitchie,

This is what needs to happen when query by a form.
1) The has to be opened and the criteria is filled in. In your case, your
combo box with "Project2001" selected.
2) Need to open the query with the query criteria use the form's value.
Your query should look like "select * from table where criteria =
[forms]![myopenedform]![combo box];"
3) If you want macro to do the query, you can called the macro from your
form. That can be done as part of the afterupdate or a button on the form.

Hope this helps.

happywitchie said:
I have a combo box on a form and when an item is selected, I want a query to
be returned with the results filtered to the selected item.

For example, when "Project2001" is selected, the returned query should only
display the data relating to Project2001.

The code I have is:
[Parent Project]=[Forms]![Reports and Queries Form]![cmbProject]

[Parent Project] is the field in the query that I need to set the filter
criteria to.

However, the above code does not work - it says that it doesn't recognise
"[Forms]![Reports and Queries Form]![cmbProject]"

Can anyone suggest what I have done wrong? Also, where do I put this code?
At the moment I have it in a macro as follows:
OpenQuery: qryProject
ApplyFilter: [Parent Project]=[Forms]![Reports and Queries
Form]![cmbProject]

Thanks
hw
 

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