title: Onclick Export Query Results from Access to Excel
body: <p>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:</p>
  
  <pre><code>DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "ReportQuery", "C:\helloworld.xlsx", True
  </code></pre>
  
  <p>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.</p>
  
  <p>I find it hard to believe that the engine doesn't have permission. Is there a setting or something I am missing here?</p>