Reputation: 13
I would like to export Access query results to a text file with some added string in the first line of exported file.
Specifically, I would like to combine a text string:
*Abc def
with the Access query results (tab delimited):
DoCmd.TransferText acExportDelim, "Export_spec", "Export", "C:\export.txt", True, ""
and then save it as a text file.
The text string have to be in the first line of the text file, followed by access query results.
The results should looks like:
*Abc def
Header1 Header2 Header3 Header4 ...
Value1 Value2 Value3 Value4 ...
... ... ... ... ...
Upvotes: 1
Views: 704
Reputation: 123584
You will need to
One way to accomplish that would be to use a FileSystemObject
in code like this
Dim tempExportSpec as String
tempExportSpec = "C:\__tmp\tempexport.txt"
DoCmd.TransferText acExportDelim, "Export_spec", "Export", tempExportSpec, True, ""
Dim fso As New FileSystemObject
Dim finalFile As TextStream
Set finalFile = fso.CreateTextFile("C:\folder\export.txt")
finalFile.WriteLine "*Abc def"
Dim tempExport As TextStream
Set tempExport = fso.OpenTextFile(tempExportSpec, ForReading)
finalFile.Write tempExport.ReadAll
finalFile.Close
tempExport.Close
fso.DeleteFile tempExportSpec
Upvotes: 2