outputTo and whereCondition?

  • Thread starter Thread starter Jan
  • Start date Start date
J

Jan

Hi

I need to change the criteria of a query and then create a csv file with the
records that match the query. I have been trying to do this using the
DoCmd.OutputTo command. It would seem logical to use a whereCondition
statement to set the criteria for the query. Is this possible? Can anyone
tell me the syntax?

Thanks
J
 
Jan said:
Hi

I need to change the criteria of a query and then create a csv file
with the records that match the query. I have been trying to do this
using the DoCmd.OutputTo command. It would seem logical to use a
whereCondition statement to set the criteria for the query. Is this
possible? Can anyone tell me the syntax?

Thanks
J

OutputTo (as you have discovered) has no ability to dynamically apply a filter.
There are numerous work-arounds.

Have the query use a public variable or hidden form control for criteria and set
that to the desired value before calling OutputTo.

Modify the SQL of the query before the OutputTo and then set it back afterwards
(though the query could get stuck in the modified state). To avoid that you
could build a temporary "query over the query" and then put the filtering only
in the temp query (safer).

If you were using OutputTo against a form or report you can apply dynamic
filtering in the Open event based on a test that your OutputTo code can
manipulate before hand.
 
Back
Top