Byron Claiborne
Byron Claiborne

Reputation: 215

Onclick Export Query Results from Access to Excel

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:

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.

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

Upvotes: 2

Views: 3469

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123654

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.

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

Upvotes: 2

Related Questions