Named Query Question

  • Thread starter Thread starter Randy Fritz
  • Start date Start date
R

Randy Fritz

Hello NG

Can you use a SQL Query as a Table in code without having the query
saved in the queries collection? I know that I could in code write a query
definition save the query to the collection then run an SQL using that Query
then Delete the Query from the collection after I am done with it as a work
around but I was hoping someone could tell me if you could use an SQL in the
FROM Clause directly.

Randy
 
Can you use a SQL Query as a Table in code without having the query
saved in the queries collection?

You can create a temporary querydef object:

Dim qd As DAO.Querydef
Dim rs As DAO.Recordset
strSQL = <your SQL string>
Set qd = db.CreateQuerydef("", strSQL)
Set rs = qd.OpenRecordset


You can then do what you like with the recordset. The "" simply makes
this an unnamed querydef, and it need not (indeed cannot) be stored in
the Queries list.
 
Back
Top