Others

How to Export an Access Query to a Date-Named Excel File

Jason MillerJason Miller Nov 3, 2026 869 views

Question details

The user needs to export a Microsoft Access query to an Excel file where the output filename automatically includes the current month and year.

How to Export an Access Query to a Date-Named Excel File
Product
Microsoft Access
Device & OS
not provided
Scenario
Automating the export of database queries to uniquely dated spreadsheet reports via macro or VBA.
Observed behavior
The query needs to be exported with a dynamic filename, such as 'QA and CQC monitor January 2020.xlsx', instead of a fixed static filename.
Before you start

Ensure you have basic familiarity with Microsoft Access VBA and know how to assign events to form buttons.

Solution 1Recommended

Use VBA and DoCmd.TransferSpreadsheet

This is the most reliable way to dynamically generate a filename with the current date and export your query.

By using a standard Access module, you can leverage the Format function to append the current month and year to your filename string before executing the export command.

1
Create a Public Function

In Access, go to Database Tools, open a standard module, and create a new Public Function for your export task.

2
Define the File Path

Construct the path string using VBA. For example, type: strPath = "C:\YourPath\QA monitor " & Format(Date, "mmmm yyyy") & ".xlsx"

3
Execute the Export

Add the command: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "YourQueryName", strPath to trigger the data export.

4
Assign to a Form Button

Open your Access Form in Design View, select your export button, and assign this function to its On Click event property.

Use VBA and DoCmd.TransferSpreadsheet
Path Verification: Always ensure the destination folder exists on your computer before running the code to avoid runtime errors.
Free Microsoft Office alternative

Manage Exported Spreadsheet Data with WPS Office

While Microsoft Access is required for the initial database query, you can use WPS Office as a free, lightweight alternative to open, edit, and analyze the resulting Excel spreadsheets. WPS Spreadsheet offers a familiar UI and seamless data processing capabilities.

  1. 1. Download WPS Office: Install the free WPS Office suite on your PC or Mac.
  2. 2. Open Your Exported Data: Locate the date-named Excel file generated by Access and open it directly in WPS Spreadsheet.
  3. 3. Analyze and Report: Use the robust built-in charting and data analysis tools to refine your reports.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv).Lightweight and fast, opening large database exports instantly.Familiar user interface that requires no learning curve.Free alternative for advanced spreadsheet formatting, pivot tables, and charting.
microsoft office alternative - wps office

Frequently Asked Questions

Why does clicking my Access form button do nothing after adding the code?

Verify that the On Click event property of the button is correctly set to '[Event Procedure]' and that it successfully calls your function. Additionally, ensure your VBA procedure is declared as 'Public Function' inside a standard module, rather than being hidden in a form module.

Can I automatically create a chart in Excel during the Access export process?

The DoCmd.TransferSpreadsheet function only exports raw data. To generate charts automatically, you must either export the data to a pre-built Excel template that already contains your chart, or use Excel Object Automation in VBA to construct the chart dynamically after transferring the data.

What happens if the destination folder in my VBA code doesn't exist?

If the specified directory does not exist, the VBA code will throw a runtime error and the export will fail. You can add a 'Dir' function check in your VBA script to verify the folder path exists before executing the export, or use 'MkDir' to automatically create it.