How to get the SQL-text of Queries in Access?

P

Paul Overway

Create table named tblSQL with two fields

QueryName Text 255
SQL Memo

Then run the following code to populate the table:

Sub GetSQL()

Dim db as database
Dim rst as recordset
dim qdf as querydef

Set db = currentdb()
Set rst = db.OPenrecordset("tblSQL")

For each qdf in db.QueryDefs
With rst
.AddNew
.fields("QueryName")=qdf.Name
.fields("SQL")=qdf.SQL
.Update
End With
Next

End Sub

You should then be able to export the table to text with all of the SQL.
 
P

Peter Plumber

Hi,

I have an Access2000 datebase with a large number of views.
I would like to export all the SQL-texts into a text file.
Any Ideas?

thx

Peter
 
P

Peter Plumber

Paul said:
Create table named tblSQL with two fields

QueryName Text 255
SQL Memo

Then run the following code to populate the table:

Sub GetSQL()

Dim db as database
Dim rst as recordset
dim qdf as querydef

Set db = currentdb()
Set rst = db.OPenrecordset("tblSQL")

For each qdf in db.QueryDefs
With rst
.AddNew
.fields("QueryName")=qdf.Name
.fields("SQL")=qdf.SQL
.Update
End With
Next

End Sub
thx a lot

Btw.:
I had to add a reference to DAO

Peter
 

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