ACC2002: Reserved Error Calling ExportXML Method (285532)
The information in this article applies to:
This article was previously published under Q285532 Moderate: Requires basic macro, coding, and interoperability skills.
This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
SYMPTOMS
When you call the ExportXML method in Visual Basic for Applications, you may receive the following error message:
Runtime Error '2950': Reserved Error
CAUSE
This error is typically caused by an invalid path in the DataTarget argument of the ExportXML method. The DataTarget argument is used to specify where to save the object that is being exported.
RESOLUTION
Verify that the path in the ExportXML method is valid. You can work around this behavior by using either error handling to trap for the error or by making sure that the path exists before you call the method. Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Error Handling
For an example of how to use error handling, follow these steps:
- Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
- In the Database window, click Module on the Insert menu.
- Type or paste the following code into the module:
Function ExportXMLFile1()
'Uses error handling to trap for the 2950 error
On Error GoTo EHandler
Application.ExportXML acExportTable, "Customers", "c:\invalidpath\customers.xml"
MsgBox "ExportXML Complete!"
ExitRoutine:
Exit Function
EHandler:
If (Err = 2950) Then
MsgBox "Please check the path you are trying to save to and try again.", , "Cannot Save XML"
Else
Resume ExitRoutine
End If
End Function
- On the View menu, click Immediate Window.
- To run the function, type the following line in the Immediate window, and then press ENTER:
?ExportXMLFile1()
Checking for a Valid Path
To verify that the path that you are exporting to is valid, you can use the Dir function. If you do so, you have to parse the folder from the full path because the file that is being exported to may or may not exist. For an example of how to do so, follow these steps:
- Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
- In the Database window, click Module on the Insert menu.
- Type or paste the following code into the module:
Function ExportXMLFile2()
Dim strSaveFile As String
Dim strSavePath As String
Dim blnIsValidDir As Boolean
'Set the file name to save
strSaveFile = "c:\customers.xml"
'Retrieve just the path
strSavePath = Left(strSaveFile, InStrRev(strSaveFile, "\"))
'Does the path exist?
blnIsValidDir = (Len(Dir(strSavePath, vbDirectory)) > 0)
If Not blnIsValidDir Then
'If the path is invalid, return a warning
MsgBox "Please check the path you are trying to save to and try again.", , "Cannot Save XML"
Else
'Otherwise, export to the file
Application.ExportXML acExportTable, "Customers", strSaveFile
MsgBox "ExportXML Complete!"
End If
End Function
- On the View menu, click Immediate Window.
- To run this function, type the following line in the Immediate window, and then press ENTER:
?ExportXMLFile2()
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kberrmsg kbprb KB285532 |
---|
|