<!--
  canonical-url: https://www.avonture.be/blog/vba-access-export
  published:     2025-06-27
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Export MS Access objects

> Easily version control your MS Access database! Export all VBA code, forms, modules, queries, and reports to flat files using a simple VBS script for GitHub integration.

---
![Export MS Access objects](/img/v2/msaccess.webp)

**TL;DR**

This article introduces a VBS script for exporting all objects—forms, modules, queries, reports, and macros—from a Microsoft Access database into individual text-based files. This process allows developers to easily version control their Access application's source code using tools like Git and GitHub. The script automatically organizes the exported files into a structured `src` folder, creating a separate file for each object, making it simple to track changes and maintain a history of the database's design and logic.

A long time ago, in a previous life, I developed a lot of MS Access databases and unlike modern tools, it wasn't possible to version the code (modules, macros, queries, etc.) in a tool like Github.

These objects are an integral part of the database in the same way as the tables and their data. Everything is stored inside the `.mdb` format (or `.mda` or `.accdb`). If you want to version them, you must first extract them.

*Two other MS Access articles on this blog: [VBS - Retrieve the list of fields in a MS Access Database](/blog/vbs-msaccess-get-fields) to audit the structure, and [How to optimize an existing MS Access database](/blog/msaccess-optimize) to act on the results.*

Let's look at how to do this.

## Sample

By running `cscript vbs_access_export.vbs C:\Christophe\db1.mdb` in a DOS console, you'll get this:

```bash
Process database C:\Christophe\db1.mdb

Exporting sources to C:\Christophe\src\db1.mdb\

Export all forms
        Export form 1/2 - frmCustomers to Forms\frmCustomers.frm
        Export form 2/2 - frmInvoices to Forms\frmInvoices.frm

Export all macros
        Export macro 1/15 - mcrPrint to Macros\mcrPrint.txt
        [...]

Export all modules
        Export module 1/2 - Helper to Modules\Helper.bas
        Export module 2/2 - SQL_Server to Modules\SQL_Server.bas

Export all queries
        Export query 1/23 - qryCustomers to Queries\qryCustomers.sql
        Export query 2/23 - qryInvoices to Queries\qryInvoices.sql
        [...]

Export all reports
        Export report 1/8 - Invoice to Reports\Invoice.txt
        [...]
```

Once finished, you'll have a subfolder called `src` with one file by object so, indirectly, you've a backup of your code 👌.

## Description

My <https://github.com/cavo789/vbs_access_export> VBS script will export all code objects (forms, macros, modules, queries and reports) from a MS Access database / application to flat files on your disk.

This way, you'll get a quick backup of your code and you'll be able to synchronize your code on a versioning platform like GitHub.

The script will start MS Access (in hidden mode), open the specified database, process every code object and export them, one by one, in a `\src\your_database.mdb` folder.

The `src` folder will be automatically created if needed and you'll find a subfolder having the same name as your file (so you can have more than one exported file in the same `src` folder).

## Install

Just get a copy of the <https://github.com/cavo789/vbs_access_export> VBS script, perhaps the `.cmd` too (for your easiness) and save them in the same folder as your database.

## Usage

Just edit the `.cmd` file and you'll see how it works: you just need to run the `.vbs` with one parameter, the name of your database — the same command already shown at the top of this article.

## Conclusion

A single VBS script turns forms, modules, queries, reports and macros — everything that used to live only inside the `.mdb`/`.accdb` file — into flat files you can commit to GitHub, diff, and track like any other codebase. Working with VBA-heavy files in general? See also [MS Excel - Get the list of references used in your modules](/blog/vba-excel-list-references), [How to optimize an existing MS Access database](/blog/msaccess-optimize) and [VBS - Retrieve the list of fields in a MS Access Database](/blog/vbs-msaccess-get-fields).
