Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export SQL of ACCESS query 2010

Status
Not open for further replies.

slmehl

Technical User
Mar 13, 2001
5
US
Hello --

I want to export to text the SQL version of all queries in a 2010 mdb.

This code runs in 2003. VBA is not my strength.

Can anyone give me pointers on how to adapt it to 2010?

The first error message is on this line:

Dim dbs As Database ... "User-defined type not defined"

Thanks in advance for any help.

Public Function ExportObjects()
Dim dbs As Database
Dim ctr As Container
Dim doc As Document
Dim qdf As QueryDef

Dim ff As Integer
Dim lngCount As Long
Dim strPath As String
Dim strFileDoc As String
Dim strFileNumber As String
Dim strFileObjectLog As String

On Error GoTo ExportObjects_Error

strPath = "U:\objects\"

strFileObjectLog = "object.lst"

ff = FreeFile()
strFileNumber = "#" & CStr(ff)
lngCount = 0
Open strPath & strFileObjectLog For Output As ff
Set dbs = CurrentDb

For Each qdf In dbs.QueryDefs
lngCount = lngCount + 1
strFileDoc = strPath & qdf.Name & ".sql"
Debug.Print lngCount, strFileDoc
SaveAsText acQuery, qdf.Name, strFileDoc '& qdf.Name & ".sql"
Print #ff, acQuery & Chr$(9) & qdf.Name & Chr$(9) & qdf.Name & ".sql"
Next qdf

End Function
 
You should add a reference to the DAO object library.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top