By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,761 Members | 1,879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,761 IT Pros & Developers. It's quick & easy.

Query criteria that isn't bound to a single form or report

P: n/a
I have an Access query that gets an ID value from an open form.
Something like

SELECT * from tablename WHERE ID=openFormName.ID;

But now, I want to also run the query by handing it the ID from a
report.

How do I set the Criteria for a query so it can take the ID value from
either the form or the report (or any source I call the query from)?

Many thanks for considering my question,
Megan Golding

Mar 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Megan, to make it flexible, leave the criteria out of the query.
Instead, use the WhereCondition of OpenReport.

For a couple of examples of building the WhereCondition string, see:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
and:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Each form can then build its own critiera, and re-use the same report.

You can actually make this very flexible, offering the user lots of choices
to filter the report, and just building the WhereCondition from the controls
where the user actually entered something. For an example of that, download
the example database in this link:
http://allenbrowne.com/unlinked/Search2000.zip
The example is just a few kilobytes, and requires Access 2000 or later. The
example shows how to build the string to apply as the Filter for a search
form, but the technique is identical for building the WhereCondition for
OpenReport.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<mg******@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I have an Access query that gets an ID value from an open form.
Something like

SELECT * from tablename WHERE ID=openFormName.ID;

But now, I want to also run the query by handing it the ID from a
report.

How do I set the Criteria for a query so it can take the ID value from
either the form or the report (or any source I call the query from)?

Many thanks for considering my question,
Megan Golding

Mar 2 '06 #2

P: n/a
Oh, my. That's so simple. Thanks for pointing me to the WhereCondition
feature!

Thank you very much for the great response and pointers.

Megan Golding

Mar 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.