我想将Access查询结果导出到文本文件中,并在导出文件的第一行添加一些字符串。
具体来说,我想组合一个文本字符串:
*Abc def
使用Access查询结果(制表符分隔):
DoCmd.TransferText acExportDelim, "Export_spec", "Export", "C:\export.txt", True, ""
然后将其另存为文本文件。
文本字符串必须位于文本文件的第一行,然后是访问查询结果。
结果如下:
*Abc def
Header1 Header2 Header3 Header4 ...
Value1 Value2 Value3 Value4 ...
... ... ... ... ...
答案 0 :(得分:2)
你需要
实现这一目标的一种方法是在代码中使用FileSystemObject
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