Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exporting multiple access tables to single XML

Tags:

xml

vba

ms-access

I have multiple Microsoft Access tables that I want exported into a single XML file. How do I manipulate the order and hierarchy of the tables into the XML structure that I want? In essence, I want to be able to reverse the import XML process, which automatically breaks down the data into multiple tables. I can use VBA, SQL, and any built-in export function at my disposal.

like image 828
david wingerslaugh Avatar asked May 07 '12 18:05

david wingerslaugh


2 Answers

I use the attached to produce a 3 million line nested xml in about five minutes.

There are two key items,

1) a simple piece of VB,

Public Function Export_ListingData()

    Dim objOtherTbls As AdditionalData

    On Error GoTo ErrorHandle
    Set objOtherTbls = Application.CreateAdditionalData
    objOtherTbls.Add "ro_address"
    objOtherTbls.Add "ro_buildingDetails"
    objOtherTbls.Add "ro_businessDetails"
    objOtherTbls.Add "ro_businessExtras"
    objOtherTbls.Add "ro_businessExtrasAccounts"
    objOtherTbls.Add "ro_businessExtrasAccom"
    objOtherTbls.Add "ro_businessExtrasAccom2"

    Application.ExportXML ObjectType:=acExportTable, _
                DataSource:="ro_business", _
                DataTarget:="C:\Users\Steve\Documents\Conversions\ListData.xml", _
                AdditionalData:=objOtherTbls
Exit_Here:
        MsgBox "Export_ListingData completed"
        Exit Function
ErrorHandle:
        MsgBox Err.Number & ": " & Err.Description
        Resume Exit_Here
End Function

2) Linking the tables in relationship manager using joins from primary to FOREIGN keys.

If there are no relationships the code will produce a sequential xml file, if there are relationships between primary keys you will get a 31532 error and the data export will fail.

like image 82
rathbst Avatar answered Nov 18 '22 06:11

rathbst


here is the solution via VBA:
http://msdn.microsoft.com/en-us/library/ff193212.aspx

create a from and put a button on it. right click on the button and choose "build event" and past the following code:

Dim objOtherTbls As AdditionalData


Set objOtherTbls = Application.CreateAdditionalData

'Identify the tables or querys to export
objOtherTbls.Add "internet"
objOtherTbls.Add "mokaleme"

'Here is where the export takes place
Application.ExportXML ObjectType:=acExportTable, _
DataSource:="internet", _
DataTarget:="C:\myxml.xml", _
AdditionalData:=objOtherTbls

MsgBox "Export operation completed successfully."

you have to type the name of your tables here and between quotations:

   objOtherTbls.Add "internet"
    objOtherTbls.Add "mokaleme"

    DataSource:="internet"
like image 39
PersianMan Avatar answered Nov 18 '22 06:11

PersianMan