How to Export an Access Table to XML Using VBA
Question details
The user needs to programmatically export a Microsoft Access table to an XML file format using a VBA macro.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Exporting database tables to an XML format for data interchange, storage, or integration with other systems.
- Observed behavior
- Attempting to use the DoCmd.TransferText method fails for XML exports because that specific command only supports standard text and CSV file formats.
Ensure you have the correct write permissions for the destination folder path in your VBA script to prevent runtime errors during the XML export.
Use the Application.ExportXML Method
The recommended approach for exporting a single Access table directly to an XML file using a VBA macro.
The Application.ExportXML method is specifically designed for XML generation and requires explicit object, source, and destination arguments to function correctly.
Open your Microsoft Access database and press ALT + F11 to launch the Visual Basic for Applications (VBA) Editor.
Click 'Insert' from the top menu and select 'Module' to create a new script, or open an existing macro where you want to add the export functionality.
Enter the following command: Application.ExportXML ObjectType:=acExportTable, DataSource:="AutoSysTabell", DataTarget:="C:\Autosys\AutosysXML-Melding.xml"
Modify the DataSource table name and the DataTarget file path to match your specific database and desired folder location, then click the 'Run' button (or press F5) to generate the XML file.

Export Multiple Related Tables Using AdditionalData
Use this advanced method when you need to include related database tables in the same XML export file.
Use the DoCmd.ExportXML Method
A simplified alternative command that achieves the same XML export result for standard database tables.
Discover WPS Office for Your Document Tasks
While Microsoft Access handles complex database management, WPS Office provides a lightweight, highly compatible, and free alternative for all your word processing, spreadsheet, and presentation tasks. Seamlessly open, edit, and save Microsoft Office files without a heavy subscription.
- 1. Visit the official website: Go to the official WPS Office website on your web browser.
- 2. Download the installer: Click the 'Free Download' button to get the latest installation package for your operating system.
- 3. Install and launch: Run the downloaded installer and follow the simple on-screen instructions to set up your free office suite.

Frequently Asked Questions
Why does DoCmd.TransferText fail when exporting to XML?
The DoCmd.TransferText method is specifically designed for exporting to plain text files (.txt) and CSV files. To handle the structured tags and data formatting required by XML files, MS Access VBA strictly requires the ExportXML method instead.
Can I export MS Access forms or queries to XML using VBA?
Yes. You can change the ObjectType argument in the ExportXML method. Instead of acExportTable, you can specify acExportQuery, acExportForm, or acExportReport depending on the database object you want to export.
What is the purpose of the AdditionalData object in ExportXML?
The AdditionalData object allows you to append data from multiple related tables into a single XML export file. This is critical for preserving your database's relational structures (like parent-child table linkages) when exporting data for use in external applications.




