Cloning a Recordset

Cloning a Recordset

You can use Clone() method of ADODB.Recordset object to create a duplicate recordset object from an existing recordset object. An important advantage of this method is that instead of creating two independent recordsets, it creates two recordset objects that point to the same recordset. This feature allows you to change the current record in the clone, while keeping the current record same in the original recordset object or vice versa.

Using this method is more efficient than creating a new recordset with the same source definition: It saves an extra trip to the database server. You should note that you can only clone a Recordset object that supports bookmarks. If you make changes to a recordset, then those changes will be visible in all clones. If you execute Requery on the original Recordset, the clones will no longer be synchronized to the original. Similarly if you close the original recordset then it won’t close the clones or vice versa. Here is a sample method that makes use of Clone method:

 Private Sub CloneRecordset(ByVal SourceRecordset As 
ADODB.Recordset, ByRef TargetRecordset As ADODB.Recordset) ' Only boomarkable recordsets support Clone method If (SourceRecordset.Supports(adBookmark)) Then Set TargetRecordset = SourceRecordset.Clone() End IfEnd Sub
See also  11 Effective Keyword Research Tools and Techniques

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist