ACC2002: Reserved Error Calling ExportXML Method (285532)



The information in this article applies to:

  • Microsoft Access 2002

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:
  1. Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  2. In the Database window, click Module on the Insert menu.
  3. 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
    					
  4. On the View menu, click Immediate Window.
  5. 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:
  1. Open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  2. In the Database window, click Module on the Insert menu.
  3. 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
    					
  4. On the View menu, click Immediate Window.
  5. To run this function, type the following line in the Immediate window, and then press ENTER:
    ?ExportXMLFile2()
    					

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

  1. Open the sample database Northwind.mdb or the sample project NorthwindCS.adp, and then create a new module.
  2. Type or paste the following code into the Visual Basic Editor:
    Sub ExportXMLInvalidPath
        Application.ExportXML acExportTable, "Customers", "C:\Invalid\Customers.xml"
    End Sub
    					
  3. 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 "Symptoms" section of this article.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kberrmsg kbprb KB285532