enumerate queries

G

Guest

I'm looking for a method to enumerate all queries and their SQL statements in
an access db.

Essentially, I'm looking to create a table with three columns: autoID,
QueryName, SQL statement.

I imagine this is rather straightforward but I'm not sure how to go about
doing it. As there are several dozen queries in the db I am documenting this
would seem to be a quicker option than manually copying all the queries' SQL
statements into a Word doc.
 
G

Guest

This is untested air code written in haste, so I will not guarantee it, but
it is the basic idea of how to do this.

Dim dbf as DAO.Database
Dim rst as DAO.Recordset
Dim qdfs as QueryDefs
Dim qdf As QueryDef
Dim strSQL As String
Dim strName as String

Set dbf = Currentdb
Set rst = dbf.OpenRecordset("MySQLTable", dbOpenDynaset)
Set qdfs = dbf.QueryDefs
Set qdf = dbf.QueryDef

For each qdf in qdfs
strName = qdf.Name
strSQL = qdf.SQL
With rst
.AddNew
![QueryName] = strName
![QuerySQL] = strSQL
.Update
End With
 
G

Guest

Thanks, this provides some good information.

Klatuu said:
This is untested air code written in haste, so I will not guarantee it, but
it is the basic idea of how to do this.

Dim dbf as DAO.Database
Dim rst as DAO.Recordset
Dim qdfs as QueryDefs
Dim qdf As QueryDef
Dim strSQL As String
Dim strName as String

Set dbf = Currentdb
Set rst = dbf.OpenRecordset("MySQLTable", dbOpenDynaset)
Set qdfs = dbf.QueryDefs
Set qdf = dbf.QueryDef

For each qdf in qdfs
strName = qdf.Name
strSQL = qdf.SQL
With rst
.AddNew
![QueryName] = strName
![QuerySQL] = strSQL
.Update
End With


Dave F said:
I'm looking for a method to enumerate all queries and their SQL statements in
an access db.

Essentially, I'm looking to create a table with three columns: autoID,
QueryName, SQL statement.

I imagine this is rather straightforward but I'm not sure how to go about
doing it. As there are several dozen queries in the db I am documenting this
would seem to be a quicker option than manually copying all the queries' SQL
statements into a Word doc.
 

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