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
Post a Comment