我有多个Microsoft Access表,我想将其导出到单个XML文件中。如何将表的顺序和层次结构操作到我想要的XML结构中?从本质上讲,我希望能够反转导入XML过程,该过程会自动将数据分解为多个表。我可以使用VBA,SQL和任何内置的导出功能。
答案 0 :(得分:5)
我使用附件在大约五分钟内生成一个300万行嵌套xml。
有两个关键项目,
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)使用从主键到FOREIGN键的连接来链接关系管理器中的表。
如果没有关系,代码将生成顺序xml文件(如果有) 主键之间的关系将导致31532错误,数据导出将失败。
答案 1 :(得分:3)
这是通过VBA的解决方案:
http://msdn.microsoft.com/en-us/library/ff193212.aspx
创建一个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."
您必须在此处和引文之间键入表名:
objOtherTbls.Add "internet"
objOtherTbls.Add "mokaleme"
DataSource:="internet"