Submitted By: Kent Finkle

Saves an Access Recordset as an XML file.

Visual Basic
Edit|Remove
'*  Script name:    SaveAsXml.vbs
'*  Created on:     9:27 PM 8/8/2006
'*  Author:         Kent Finkle
'*  Purpose:        Save an Access Recordset as XML.

Option Explicit

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adPersistXML = 1

Dim objConnection
Dim objRecordSet
Dim Fso
Dim strFileName

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
Set Fso = CreateObject("Scripting.FileSystemObject")

objConnection.Open "Provider= Microsoft.Jet.OLEDB.4.0; " & _
    "Data Source=C:\Scripts\Test.mdb"

objRecordSet.Open "SELECT * FROM Hardware", objConnection, _
    adOpenStatic, adLockOptimistic
    
strFileName = "c:\scripts\mydata.xml"
    
If Fso.FileExists(strFileName) Then
    Fso.DeleteFile strFileName
End If
    
objRecordSet.Save strFileName, adPersistXML

objRecordSet.Close

objConnection.Close