Copying an ADO RecordSet in Visual Basic

The ADO RecordSet object’s Clone method does a great job of making a duplicate copy of the RecordSet, with one major caveat: any changes to the clone are duplicated on the original. It’s more like a shallow copy than a deep copy.

To make an actual copy of a disconnected ADO RecordSet in Visual Basic, use a method like the one shown below, which was largely taken from Francesco Balena’s article on devx.com:

Private Function CopyRecordset(rsSource As ADODB.Recordset) As ADODB.Recordset
    Dim rs As ADODB.Recordset
    Dim pb As New PropertyBag
    ‘ create a copy of the recordset
    pb.WriteProperty “rs”, rsSource
    Set rs = pb.ReadProperty(“rs”)
    ‘ release the memory
    Set pb = Nothing
    Set CopyRecordset = rs
End Function
Bookmark and Share

Related Posts

A hundred years from now it will not matter what my bank account was, the sort of house I lived in, or the kind of car I drove. But the world may be different, because I was important in the life of a [child].

-- Forest E. Witcraft

Post a Comment

Your email is never published nor shared. Required fields are marked *