简体   繁体   English

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

[英]Exporting MS-Access form results to Excel?

I'm kind of new to Access.我对 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.我在将 MySQL 和 Oracle 与 PHP 集成以创建基于 Web 的数据库搜索引擎方面有一些经验,但我很难理解 Access 的某些概念。

I've got a small database with around 200 entries with 20 fields each.我有一个小型数据库,其中包含大约 200 个条目,每个条目有 20 个字段。 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?)我编写了一个表单来搜索它,使用 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).我希望能够添加一个按钮来将这些结果导出到 excel(或 csv 或选项卡或其他任何东西,这并不重要)。 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?还是我做错了?

If at all required, I can provide more details.如果需要,我可以提供更多细节。

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.如果您愿意,您可以选择不同的 OutputFormat 而不是 Excel。 Look at Access' Help topic for the OutputTo method to see the available choices.查看有关 OutputTo 方法的 Access 帮助主题以查看可用选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM