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



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.

<mgolding@xxxxxxxxx> wrote in message
news:1141254709.810998.312340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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


.



Relevant Pages

  • Re: problem with form...
    ... If yes, you only need one report, and one query, or no ... > WhereCondition argument in the DoCmd.OpenReport. ... > This will produce a message for the user and cancel opening the report, ...
    (microsoft.public.access.forms)
  • Re: Create Report Using Form Parameters
    ... It might be easier to omit the WHERE clause from the query, and build a string to use in the WhereCondition of OpenReport. ... The last one applies its filter to a form, but creating the filter string for a report is identical. ...
    (microsoft.public.access.forms)
  • Re: Selections on Report
    ... If the report is based on a Totals query, you can use this technique on the fields that have Group By in the Total row in query design. ... If you need to be able to do that, you can either use a mix of both techniques (the WhereCondition for the Group By fields, and the query parameters for the Where fields), or you can build the entire SQL statement in the Open event of the report, and assign it to the report's RecordSource. ... There's a downloadable example that shows how to make a search form like ...
    (microsoft.public.access.reports)
  • Re: How to get around "filter too long" run-time error?
    ... Instead of using the wherecondition argument, ... the OpenReport method to pass the name of a saved query. ... you to filter a report without limitation on the size of the WHERE clause. ... How do I save a query from the form with the selected list items? ...
    (microsoft.public.access.formscoding)
  • Re: OpenReport Method
    ... Let's say I run a report like so: ... When the report is running the OnOpen event, I want to see what the value of ... >>Is there a way to access the wherecondition parameter from the OpenReport ...
    (microsoft.public.access.reports)