使用FileSystemObject将查询输出写入文本文件

时间:2012-02-27 16:28:23

标签: ms-access-2007 access-vba filesystemobject

有没有办法使用FileSystemObject将查询输出写入文本文件?

1 个答案:

答案 0 :(得分:1)

查询结果的格式是什么?如果它是一个简单的字符串,你可能会做这样的事情,或者你可能需要提取你需要的位。

以下是使用filesystemobject将字符串写入文本文件的代码:

Const fsoForAppend = 8

Dim objFSO
Dim queryResult

queryResult = 'OMG no results'

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\path\to\logfile.txt", fsoForAppend)

'Write the results to the textfile
objTextStream.WriteLine queryResult

'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
相关问题