使用vba-MS Access将查询结果导出到文本文件 [英] Exporting a query result into a text file using vba-MS Access
本文介绍了使用vba-MS Access将查询结果导出到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MS Access 2010中有一个表,我想将查询结果导出到文本文件中(用户指定了路径,并且该文本文件应保存在此路径中)
I have a Table in MS Access 2010 and I want to export the result of a query into a text file( the user specified a path and this Textfile should be saved in this Path)
这是我的查询:
SELECT Name FROM MyTable
,我想将每个名称都放在文本文件的单独一行中.如何在VBA中做到这一点?
and I want to have each name in a seprate row in a text file. How can I do that in VBA?
推荐答案
在这种特殊情况下,最直接的方法是这样的:
In this particular case the most straightforward approach would be something like this:
Sub ExportToText()
Dim rst As DAO.Recordset
Open "C:\__tmp\names.txt" For Output As #1
Set rst = CurrentDb.OpenRecordset("SELECT [Name] FROM MyTable", dbOpenSnapshot)
Do While Not rst.EOF
Print #1, rst!Name
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Close #1
End Sub
这篇关于使用vba-MS Access将查询结果导出到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文