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

  • Thread starter Thread starter Paul Overway
  • Start date Start date
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.
 
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
 
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
 
Back
Top