Save Filter As Query

  • Thread starter Thread starter Chris Sergent
  • Start date Start date
C

Chris Sergent

I am trying to save a filter by form as a query so that my
report can reference the query with the applied filter. I
do not want the prompt for the user to enter the name of
the query, I want VBA to name the query but the normal
save command does not work and the save as query provides
a prompt. The name of the report is rptTest. The query is
named qryTest and the form is frmTest.

I filter by form on frmTest which is based on qryTest. I
would like it to create a query named qryTest1 which would
be the source data for rptTest and do not want any
prompts. Does anyone know a solution to this problem? Any
help would be greatly appreciated.

Chris
 
There may be a problem here. The form has an underlying
RowSource which may itself be a SQL statement including a
WHERE clause.
If you just want to save the filter that is easy. You can
pick up the filter using, say
sqlWhere = Me.Filter
and then save it somewhere. I often use this to apply a
filter to an associated report based on the selection on
the form.
eg DoCmd.OpenReport <ReportName>,acPreview,,Me.Filter
(make sure the filter goes into the WHERE part of the
report parameters)
If you want to save the entire RowSource AND the filter to
use to generate a display this becomes more problematic as
you will have to parse the RowSource, check whether there
is any WHERE clause in there and if so merge it with the
Form filter
HTH
Terry
 
Back
Top