How to export query, subform from MS Access to Excel using VBA

This tutorial is going to show you how to export a MS Access query or a subform to Microsoft Access using VBA code. Too export subform or query, we can use DoCmd.OutputTo method. Its a pretty simple code to get the query exported to Excel and it will automatically opened in Excel after the export process is completed.

Here is the code:

[codesyntax lang=”vb”]

DoCmd.OutputTo acOutputQuery, "Q_Export_DHAssay to excel", acFormatXLS, "E:\test.xls", True


Change the Q_Export_DHAssay to excel” with your query. E:\test.xls is the output file.


Leave a Reply

Your email address will not be published. Required fields are marked *