Change Query Object Criteria via code?

J

Joel

TIA very much!

Is it possible to change an existing query object's criteria via VB code?
If so how might it be done??

Thanks again,

Joel
 
A

Allen Browne

You can't just change the criteria, but you can replace the SQL statement.

Example, changing the SQL statement of Query1:
Dim strSql As String
strSql ="SELECT Table1.* FROM Table1;"
CurrentDb.QueryDefs("Query1").SQL = strSql

Depending where you are going with this query, it might be easier to set the
Filter property of a form, or use the WhereCondition of OpenReport.
 
J

Joel

Thanks Allen:

Couple of things, I would guess that one could build a Where clause based on
a variable?

Can the QueryDef be used as a source for a report so Query1 in your example
can become the record source for a report?

Thanks,

Joel
 
J

Joel

Thanks Allen:

I already have a set of hierarchial queries that need to be run with several
different criteria set in the underlying query. I would let to have a form
set with command button to set the criteria and then open a report based on
the query with the set criteria.

Joel
 
Top