Export an Access Table to Excel with FileDialog
Question details
Select an Excel output path in an Access form, display it in a text box, and export a table to that path.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A form button should open a Save As dialog and export an Access table as an Excel workbook.
- Observed behavior
- The selected file path should appear in the form text box, and the table should be exported to an XLSX file.
Open the database in Microsoft Access and confirm that the table and form text box names match those used in the code. Enable database content if needed so the form's VBA code can run.
Select an XLSX path and export the Access table
Use this form-button procedure to capture a Save As path and export the table with column headings.
Open the form in Design View, select the export button, and use its On Click property to create an Event Procedure. Replace the procedure body in the VBA editor with the code below.
Use the following procedure, replacing cmdExport, txt_FilePath, and tbl_Contact with your actual button, text box, and table names if they differ: Private Sub cmdExport_Click() Dim fd As Object Dim outputPath As String Set fd = Application.FileDialog(2) If fd.Show <> -1 Then MsgBox "Export canceled." Exit Sub End If outputPath = fd.SelectedItems(1) If LCase$(Right$(outputPath, 5)) <> ".xlsx" Then MsgBox "Please select a file name ending in .xlsx." Exit Sub End If Me!txt_FilePath = outputPath DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "tbl_Contact", outputPath, True End Sub
Save the form, switch to Form View, and click the export button. In the Save As dialog, choose a writable folder and enter a file name ending in .xlsx.

Open and edit exported Excel files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for an easy transition. After exporting from Access, open the workbook in WPS Spreadsheets to review or edit it. WPS does not run the Access FileDialog or TransferSpreadsheet code.

Frequently Asked Questions
What happens if I cancel the Save As dialog?
The FileDialog Show method returns a value other than -1. The example displays an export-canceled message and exits before calling TransferSpreadsheet.
Why does the file name need to end in .xlsx?
The example uses acSpreadsheetTypeExcel12Xml, which exports an Excel workbook in XLSX format. Enter an .xlsx file name in the Save As dialog so the extension matches the selected export format.
How do I export a different table?
In the DoCmd.TransferSpreadsheet call, replace "tbl_Contact" with the name of the table you want to export.
Does the export include column headings?
Yes. The final True argument in DoCmd.TransferSpreadsheet includes field names as column headings in the exported worksheet.




