Microsoft KB Archive/285532

= ACC2002: Reserved Error Calling ExportXML Method =

Article ID: 285532

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



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, &quot;Customers&quot;, &quot;c:\invalidpath\customers.xml&quot; MsgBox &quot;ExportXML Complete!&quot; ExitRoutine: Exit Function EHandler: If (Err = 2950) Then MsgBox &quot;Please check the path you are trying to save to and try again.&quot;,, &quot;Cannot Save XML&quot; 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 </ol>

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: <ol> Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.</li> In the Database window, click Module on the Insert menu.</li>  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 = &quot;c:\customers.xml&quot; 'Retrieve just the path strSavePath = Left(strSaveFile, InStrRev(strSaveFile, &quot;\&quot;)) 'Does the path exist? blnIsValidDir = (Len(Dir(strSavePath, vbDirectory)) > 0) If Not blnIsValidDir Then 'If the path is invalid, return a warning MsgBox &quot;Please check the path you are trying to save to and try again.&quot;,, &quot;Cannot Save XML&quot; Else 'Otherwise, export to the file Application.ExportXML acExportTable, &quot;Customers&quot;, strSaveFile MsgBox &quot;ExportXML Complete!&quot; End If End Function </li> On the View menu, click Immediate Window.</li>  To run this function, type the following line in the Immediate window, and then press ENTER: ?ExportXMLFile2 </li></ol>

<div class="moreinformation_section">

MORE INFORMATION
You can export XML through the user interface or programmatically by using the ExportXML method of the Application object. However, to be able to do so, the folder where you save the file must exist.

Steps to Reproduce the Behavior
<ol> Open the sample database Northwind.mdb or the sample project NorthwindCS.adp, and then create a new module.</li>  Type or paste the following code into the Visual Basic Editor: Sub ExportXMLInvalidPath Application.ExportXML acExportTable, &quot;Customers&quot;, &quot;C:\Invalid\Customers.xml&quot; End Sub </li>  Type the following line in the Immediate window, and then press ENTER: ExportXMLInvalidPath Note that you receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article. </li></ol>

Additional query words: prb

Keywords: kberrmsg kbprb KB285532

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.