1

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?

1
  • 2
    What exactly are you having a problem with? Getting the SQL? Creating a text file? Commented Aug 22, 2012 at 18:39

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

If you have the exporting string to a text file figured out, you can get the SQL text of a query from:

Dim strSQL as string
strSQL = CurrentDb.QueryDefs("Your query name here").SQL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.