I currently export the data from a passthrough query to a text using VBA in access and I would like to add to the VBA. Once it exports the data I would then like it to export the actual sql query to a seperate text. Does anyone know how to add this?
2 Answers
You can use the FileSystemObject. The example below uses late binding, but you can set a reference to the Windows Script Host and use the commented types.
Dim fs As Object ''FileSystemObject
Dim tsOut As Object ''TextStream
sFileOut = "z:\docs\FileOut.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set tsOut = fs.OpenTextFile(sFileOut, 8) ''ForAppending
''Or
'' Set tsOut = fs.CreateTextFile(sFileOut, True) ''Overwrite
sSQL = CurrentDB.QueryDefs(qry).SQL
tsOut.WriteLine sSQL
tsOut.Close