VB and VBA Users Source Code: Loading and saving ADO recordsets to XML files
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Loading and saving ADO recordsets to XML files
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, April 15, 2003
Hits:
1572
Category:
Database/SQL/ADO
Article:
The following routines show how to load and save ADO recordsets to XML files: 'Purpose : Loads an ADO recordset from an XML file 'Inputs : sPath The path and file name of the XML file. 'Outputs : Returns a copy of the recordset on success, or nothing on failure. 'Author : Andrew Baker (copyright www.vbusers.com) 'Date : 25/03/2001 'Notes : Function RsLoadFromXML(sPath As String) As Recordset Dim oStream As ADODB.Stream, oRsLoad As ADODB.Recordset On Error GoTo ErrFailed Set oRsLoad = New ADODB.Recordset oRsLoad.CursorLocation = adUseClient Set oStream = New ADODB.Stream 'Open stream oStream.Open 'Load stream oStream.LoadFromFile sPath 'Open recordset using stream oRsLoad.Open oStream Set RsLoadFromXML = oRsLoad 'Close the stream oStream.Close Set oStream = Nothing Set oRsLoad = Nothing Exit Function ErrFailed: Debug.Print Err.Description Debug.Assert False Set RsLoadFromXML = Nothing End Function 'Purpose : Saves an ADO recordset to an XML file 'Inputs : sPath The path save the XML file to. 'Outputs : Returns True on success, else returns False 'Author : Andrew Baker (copyright www.vbusers.com) 'Date : 25/03/2001 'Notes : Function RsSaveToXML(oRsSave As Recordset, sPath As String) As Boolean Dim oStream As ADODB.Stream On Error GoTo ErrFailed 'Create stream Set oStream = New ADODB.Stream 'Save recordset to stream oRsSave.Save oStream, adPersistXML 'Save stream to file oStream.SaveToFile sPath, adSaveCreateOverWrite Set oStream = Nothing RsSaveToXML = True Exit Function ErrFailed: Debug.Print Err.Description Debug.Assert False RsSaveToXML = False End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder