vba 将多个访问表导出到单个 XML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10486948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:03:46  来源:igfitidea点击:

exporting multiple access tables to single XML

xmlms-accessvba

提问by david wingerslaugh

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.

我有多个 Microsoft Access 表要导出到一个 XML 文件中。如何将表的顺序和层次结构处理成我想要的 XML 结构?本质上,我希望能够逆向导入 XML 过程,该过程会自动将数据分解为多个表。我可以随意使用 VBA、SQL 和任何内置导出函数。

回答by rathbst

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

我使用附件在大约五分钟内生成了一个 300 万行的嵌套 xml。

There are two key items,

有两个关键项目,

1) a simple piece of VB,

1)一个简单的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.

2) 使用从主键到外键的联接链接关系管理器中的表。

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.

如果没有关系,代码将生成一个连续的 xml 文件,如果主键之间存在关系,您将收到 31532 错误并且数据导出将失败。

回答by PersianMan

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

这是通过 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:

创建一个 from 并在其上放置一个按钮。右键单击按钮并选择“构建事件”并粘贴以下代码:

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"