PDA

View Full Version : Export Access Query Results to Excel and open the workbook



mykal66
04-21-2021, 01:09 AM
Good morning

A button on my database runs a query and saves the results to an Excel workbook. Does anyone know how to alter this code to automatically open the workbook after it is saved please?


DoCmd.OpenQuery "qryData", acViewNormal, acEdit
DoCmd.OutputTo acOutputQuery, "qryData", acFormatXLSX

Thank you

Mykal

OBP
04-27-2021, 03:30 PM
Workbooks.Open FileName:=(Path & docName)
Where Path is the path to the folder and dconame is the name of the excel document.

Kenneth Hobs
04-28-2021, 09:01 AM
More of an Access question but the answer is simple.

'https://docs.microsoft.com/en-us/office/vba/api/access.docmd.outputto
DoCmd.OutputTo acOutputQuery, "qryData", acFormatXLSX, , True