VB and VBA Users Source Code: Cloning or copying an ADO recordset
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Cloning or copying an ADO recordset
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, April 15, 2003
Hits:
1120
Category:
Database/SQL/ADO
Article:
The code below shows how to copy/clone an existing ADO recordset. This functionality can be useful if you want to keep an copy of the data before the user makes any changes (note, you can also use the oRs.Fields(x).OriginalValue property for this). 'Purpose : Creates a copy an existing client side ADO recordset 'Inputs : oRs The recordset to copy '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 RsClone(oRs As ADODB.Recordset) As Recordset Dim oStream As ADODB.Stream, oRsClone As ADODB.Recordset On Error GoTo ErrFailed If oRs.CursorLocation = adUseClient Then Set oStream = New ADODB.Stream oRs.Save oStream, adPersistXML Set oRsClone = New ADODB.Recordset oRsClone.Open oStream Set oStream = Nothing Set RsClone = oRsClone Set oRsClone = Nothing Else Debug.Print "Must use client side recordsets..." Debug.Assert False End If Exit Function ErrFailed: Debug.Print Err.Description Debug.Assert False Set RsClone = Nothing End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder