XML File Toolbox for MS Access – 13 Functions with the Power of XML

INI files are great for simple settings – but as soon as your application grows you need more: hierarchies, UTF-8, validation. Time for XML! This VBA toolbox brings INI-like simplicity with the power of XML: 13 functions, late binding, 32/64-bit.

In INI-Helper we looked at INI files – a simple, proven solution for configuration management. Now it’s time for the next level: XML files. INI is great for simple settings but quickly reaches its limits:

  • no hierarchical structures (only section → key → value)
  • no data validation
  • limited international character support
  • not suitable for complex data structures

XML: not just for configurations

XML is much more versatile than INI:

  • Hierarchical data structures – perfect for nested configurations, catalogs or product databases.
  • UTF-8 – all languages, special characters and even emojis.
  • Data exchange – XML is the standard for system integration.
  • Validation – check structure and content.
  • Built-in – MSXML is available in every Windows installation.

In short: INI for simple cases, XML when you need power and flexibility. All functions use late binding (no references required) and work in all Access versions (32/64-bit).

The 13 functions of the toolbox

1. XML_ReadValue – read values.

strBackendPath = XML_ReadValue(strXmlPath, "Database", "BackendPath", "")

2. XML_WriteValue – write/update values. Creates the file and section automatically; special characters are escaped automatically.

XML_WriteValue strXmlPath, "Database", "BackendPath", strSelectedPath

3. XML_PrintAll – print the complete file. Formatted in the Immediate Window – perfect for debugging.

XML_PrintAll CurrentProject.Path & "\config.xml"

4. XML_GetSections – list all sections.

Set colSections = XML_GetSections(strXmlPath)
For Each varSection In colSections
    Debug.Print "Found section: " & varSection
Next

5. XML_GetKeys – all keys of a section.

Set colKeys = XML_GetKeys(strXmlPath, "Database")
For Each varKey In colKeys
    Debug.Print varKey & " = " & XML_ReadValue(strXmlPath, "Database", CStr(varKey))
Next

6. XML_DeleteSection – delete an entire section.

If XML_SectionExists(strXmlPath, "OldModule") Then
    XML_DeleteSection strXmlPath, "OldModule"
End If

7. XML_DeleteKey – delete a single key.

XML_DeleteKey strXmlPath, "Session", "TempPassword"

8. XML_SectionExists – check a section.

If Not XML_SectionExists(strXmlPath, "DatabaseV2") Then
    ' create the section ...
End If

9. XML_KeyExists – check a key.

If Not XML_KeyExists(strXmlPath, "Features", "AutoBackup") Then
    XML_WriteValue strXmlPath, "Features", "AutoBackup", "True"
End If

10. XML_PrintStructured – structured output. Displays the XML hierarchically – ideal for documentation.

XML_PrintStructured strXmlPath

11. XML_GetAllValues – dictionary of all values.

Set dictDB = XML_GetAllValues(strXmlPath, "Database")
Debug.Print "Server: " & dictDB("Server")
Debug.Print "Port: " & dictDB("Port")
Debug.Print "Timeout: " & dictDB("Timeout")

12. XML_ValidateFormat – validate the format. Checks for malformed XML, duplicate keys and missing attributes.

If Not XML_ValidateFormat(strImportedXmlPath) Then
    MsgBox "The imported configuration is invalid!", vbCritical
End If

Checks include: file exists and is readable · XML is well-formed · no duplicate sections · no duplicate keys within a section · all sections and keys have names.

13. XML_Compare – compare two XML files. The best for versioning and migration management.

If Not XML_Compare(strOldConfig, strNewConfig) Then
    Debug.Print "Changes detected - see details in the Immediate Window"
End If

Perfect for version comparison after updates, troubleshooting, documenting changes and warnings on critical deviations.

Real-world use cases – beyond configuration

Multi-backend support:

XML_WriteValue strXmlPath, "Backends", "Production", "\\Server\DB\Prod.accdb"
XML_WriteValue strXmlPath, "Backends", "Test", "\\Server\DB\Test.accdb"
XML_WriteValue strXmlPath, "Backends", "Development", "C:\Dev\DB.accdb"
XML_WriteValue strXmlPath, "Settings", "CurrentEnvironment", "Production"

Product catalog with hierarchical structure – XML is perfect for nested data:

<?xml version="1.0" encoding="UTF-8"?>
<Product>
    <Section name="Electronics">
        <Key name="Laptop_001">Dell XPS 15, €1499, 16GB RAM</Key>
        <Key name="Laptop_002">MacBook Pro, €2299, 32GB RAM</Key>
        <Key name="Phone_001">iPhone 15, €999, 256GB</Key>
    </Section>
    <Section name="Books">
        <Key name="Programming_001">Clean Code, €35.99</Key>
        <Key name="Programming_002">Design Patterns, €42.50</Key>
    </Section>
</Product>

Export templates for reports:

XML_WriteValue strXmlPath, "ReportTemplate_Sales", "Title", "Monthly Sales Report"
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "DateFormat", "DD.MM.YYYY"
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "Columns", "Date,Customer,Amount,Status"
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "SortBy", "Amount DESC"

User preferences with UTF-8 – all special characters work flawlessly:

XML_WriteValue strXmlPath, "UI", "Language", "DE"
XML_WriteValue strXmlPath, "UI", "Theme", "Dark"
XML_WriteValue strXmlPath, "UI", "WelcomeMessage", "Willkommen zurück, Müller!"
XML_WriteValue strXmlPath, "Export", "DefaultFolder", "C:\Users\Marcus\Exporte"

System integration: exchange data with other systems that expect XML (web services, ERP). The functions automatically create valid, well-formed XML.

Special characters? Handled automatically

The module automatically escapes all special characters (&, <, >, ", ') – you don’t have to worry about it.

XML_WriteValue strXmlPath, "Test", "Ampersand", "A & B"            ' stays "A & B"
XML_WriteValue strXmlPath, "Test", "Quotes", "He said ""Hello"""   ' automatically escaped

The advantages at a glance

  • Update-proof, UTF-8 capable and hierarchical for complex, nested structures.
  • Robust: MSXML, proven for decades; universal as the standard for data exchange.
  • 32/64-bit, no dependencies (only MSXML, late binding) and with auto-escaping.

What’s next: in the next episode I’ll introduce similar tools that store, write and read data in the .yml format.

Just give it a try

Using the included testing form you can try the functions directly. You’ll find the detailed description directly in the code, well documented as usual.

Download

A VBA toolbox for MS Access with 13 functions for XML files: read, write, manage sections/keys, validate and compare – hierarchical, UTF-8 capable, via MSXML and without references.

Newsletter

Newsletter