vba MS Access:将报告导出到 CSV 文件的命令按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18279019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 22:47:49  来源:igfitidea点击:

MS Access: Command button to export a report to a CSV file

vbams-accessaccess-vba

提问by Patrick

I was wondering if this was possible. I have my main form with a bunch of tables on it, and then I have a report. Standard stuff there. The report is named Report1. What I was wondering, is there a way I can put a command button on my main form, that when pressed, will export Report1onto my desktop (or wherever I specify) in a CSV format? I would like to do this in VBA if possible. I'm not sure if I could make a macro format into CSV, but I am pretty open to any suggestions. Thank you

我想知道这是否可能。我有我的主表格,上面有一堆表格,然后我有一份报告。那里有标准的东西。该报告名为Report1。我想知道的是,有没有一种方法可以在我的主窗体上放置一个命令按钮,按下该按钮后,它将Report1以 CSV 格式导出到我的桌面(或我指定的任何地方)?如果可能,我想在 VBA 中执行此操作。我不确定是否可以将宏格式转换为 CSV,但我非常愿意接受任何建议。谢谢

回答by Johnny Bones

You can export the report's data to CSV by using DoCmd.TransferText with the report's Record Source table or named query.

您可以通过将 DoCmd.TransferText 与报表的记录源表或命名查询一起使用,将报表数据导出到 CSV。

Take a look at this: VBA DoCmd.TransferText - exporting query to .csv with user defined file path

看看这个:VBA DoCmd.TransferText - exporting query to .csv with user defined file path

回答by snibbo

A report is always based on a query.

报告始终基于查询。

You can find your query in the properties within the Design View of your report ("RecordSource").

您可以在报表设计视图(“RecordSource”)的属性中找到您的查询。

The best way should be to generate a query (based on your current report) and link that query to the report ("RecordSource") and to the export button (DoCmd.TransferText). Thereby, if you want to change your report / report data, you only need to change it once.

最好的方法应该是生成一个查询(基于您当前的报告)并将该查询链接到报告(“RecordSource”)和导出按钮(DoCmd.TransferText)。因此,如果您想更改您的报告/报告数据,您只需更改一次。