从访问Excel导出查询导出查询结果

时间:2022-07-08 15:39:03

I'm trying to do an export of data from my access db to an excel spreadsheet. Everything was smooth until I tried to code an onclick event for a form. Here is the code:

我正在尝试从我的访问数据库导出数据到excel电子表格。在我尝试为表单编写onclick事件之前,一切都很顺利。这是代码:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "ReportQuery", "C:\helloworld.xlsx", True

The error I am getting is 'Runtime Error 3051' The Microsoft Access Database engine cannot open or write to the file ... It is already opened exclusively by another user or you need permission to view and write its data.

我得到的错误是'运行时错误3051'Microsoft Access数据库引擎无法打开或写入文件...它已由其他用户独占打开,或者您需要查看和写入其数据的权限。

I find it hard to believe that the engine doesn't have permission. Is there a setting or something I am missing here?

我发现很难相信发动机没有许可。我在这里缺少什么环境或东西吗?

1 个解决方案

#1


2  

It seems that you do not have sufficient permissions to write to the root directory of drive C:. When testing, always choose a "safe" location (like your Documents folder) for creating or updating files.

您似乎没有足够的权限写入驱动器C:的根目录。测试时,请始终选择“安全”位置(如“文档”文件夹)来创建或更新文件。

BTW, you'll probably have better success if you use acSpreadsheetTypeExcel12Xml instead of acSpreadsheetTypeExcel12 when creating .xlsx files.

顺便说一下,如果在创建.xlsx文件时使用acSpreadsheetTypeExcel12Xml而不是acSpreadsheetTypeExcel12,则可能会取得更好的成功。

#1


2  

It seems that you do not have sufficient permissions to write to the root directory of drive C:. When testing, always choose a "safe" location (like your Documents folder) for creating or updating files.

您似乎没有足够的权限写入驱动器C:的根目录。测试时,请始终选择“安全”位置(如“文档”文件夹)来创建或更新文件。

BTW, you'll probably have better success if you use acSpreadsheetTypeExcel12Xml instead of acSpreadsheetTypeExcel12 when creating .xlsx files.

顺便说一下,如果在创建.xlsx文件时使用acSpreadsheetTypeExcel12Xml而不是acSpreadsheetTypeExcel12,则可能会取得更好的成功。