database 将 MS-Access 表单结果导出到 Excel?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6111510/
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-08 08:12:16  来源:igfitidea点击:

Exporting MS-Access form results to Excel?

databaseformsms-access

提问by Dirk Ferguson

I'm kind of new to Access. I've got some experience working with integrating MySQL and Oracle with PHP to create web-based database search engines, but I am having difficulty understanding certain concepts with Access.

我对 Access 有点陌生。我在将 MySQL 和 Oracle 与 PHP 集成以创建基于 Web 的数据库搜索引擎方面有一些经验,但我很难理解 Access 的某些概念。

I've got a small database with around 200 entries with 20 fields each. I've written a form to search it by using VBA to run an SQL query against the database and displays the results in datasheet mode to a different form (is this the standard way of doing this, or is there a better way?)

我有一个包含大约 200 个条目的小型数据库,每个条目有 20 个字段。我编写了一个表单,通过使用 VBA 对数据库运行 SQL 查询来搜索它,并将结果以数据表模式显示为不同的表单(这是执行此操作的标准方法,还是有更好的方法?)

I want to be able to add a button to export those results to excel (or csv or tab or whatever, it doesn't really matter). However, I'm not sure how to do this with the form results. Its easy with an entire database, but I can't find documentation on how to do this. Is there a way to do this? Or am I doing this wrong?

我希望能够添加一个按钮来将这些结果导出到 excel(或 csv 或 tab 或其他什么,这并不重要)。但是,我不确定如何处理表单结果。使用整个数据库很容易,但我找不到有关如何执行此操作的文档。有没有办法做到这一点?还是我做错了?

If at all required, I can provide more details.

如果需要,我可以提供更多详细信息。

回答by HansUp

You said "I've written a form to search it by using VBA to run an SQL query against the database and displays the results in datasheet mode to a different form".

您说“我已经编写了一个表单,通过使用 VBA 对数据库运行 SQL 查询并以数据表模式将结果显示为不同的表单来搜索它”。

If you mean an actual form in datasheet view, you can export that form's data to Excel with the DoCmd.OutputTo method.

如果您指的是数据表视图中的实际表单,则可以使用 DoCmd.OutputTo 方法将该表单的数据导出到 Excel。

DoCmd.OutputTo acOutputForm, "frmResults", acFormatXLS, _
    "C:\SomeFolder\ExportedResults.xls"

However, if you're opening a query in datasheet view, rather than an actual form, you can export the query's result set.

但是,如果您在数据表视图而不是实际表单中打开查询,则可以导出查询的结果集。

DoCmd.OutputTo acOutputQuery, "qryResults", acFormatXLS, _
    "C:\SomeFolder\ExportedResults.xls"

You can choose a different OutputFormat instead of Excel if you wish. Look at Access' Help topic for the OutputTo method to see the available choices.

如果您愿意,您可以选择不同的 OutputFormat 而不是 Excel。查看 Access 的“帮助”主题以了解 OutputTo 方法以查看可用选项。