I'm exporting a XML file from access with this code. I have to export a lot of xml files into the same carpet and they don't have to be replaced. But, in the code I don't know how to write that on DataTarget.
我正在使用此代码从访问中导出XML文件。我必须将大量的xml文件导出到同一个地毯中,并且不必更换它们。但是,在代码中我不知道如何在DataTarget上编写它。
Application.ExportXML ObjectType:=acExportTable, DataSource:="Customers", _
DataTarget:="Customer Orders.xml", _
AdditionalData:=objOrderInfo
End Sub
1 个解决方案
#1
0
You just need to retrieve the file name that the user entered and then pass it to Application.ExportXML
, something like this:
您只需要检索用户输入的文件名,然后将其传递给Application.ExportXML,如下所示:
Option Compare Database
Option Explicit
Private Sub cmdPerformExport_Click()
Dim fname As String
' Text Box control is named "txtExportFileName"
If IsNull(Me.txtExportFileName.Value) Then
MsgBox "You did not enter a file name."
Exit Sub
End If
fname = txtExportFileName.Value
Application.ExportXML _
ObjectType:=acExportTable, _
DataSource:="Customers", _
DataTarget:=fname & IIf(Right(fname, 4) = ".xml", "", ".xml"), _
AdditionalData:=objOrderInfo
End Sub
If you want additional error checking (e.g., file name only contains valid characters, drive/path exists, etc.) you will need to add that, too.
如果您想要额外的错误检查(例如,文件名只包含有效字符,存在驱动器/路径等),您还需要添加它。
#1
0
You just need to retrieve the file name that the user entered and then pass it to Application.ExportXML
, something like this:
您只需要检索用户输入的文件名,然后将其传递给Application.ExportXML,如下所示:
Option Compare Database
Option Explicit
Private Sub cmdPerformExport_Click()
Dim fname As String
' Text Box control is named "txtExportFileName"
If IsNull(Me.txtExportFileName.Value) Then
MsgBox "You did not enter a file name."
Exit Sub
End If
fname = txtExportFileName.Value
Application.ExportXML _
ObjectType:=acExportTable, _
DataSource:="Customers", _
DataTarget:=fname & IIf(Right(fname, 4) = ".xml", "", ".xml"), _
AdditionalData:=objOrderInfo
End Sub
If you want additional error checking (e.g., file name only contains valid characters, drive/path exists, etc.) you will need to add that, too.
如果您想要额外的错误检查(例如,文件名只包含有效字符,存在驱动器/路径等),您还需要添加它。