Named Query Question

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
 
J

John Vinson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top