Submitted By: Kent Finkle

Uses the Clone method to make a duplicate of a Microsoft Access recordset.

Visual Basic
Edit|Remove
'* Script name: CloneRecordSet.vbs
'* Created on: Monday, April 2, 2007
'* Author: Kent Finkle
'* Purpose: Clone an Access recordset.

Const adOpenKeyset = 1
Const adLockOptimistic = 3
Const adCmdTableDirect = 512
Const adSeekFirstEq = 1

Dim objConnection
Dim objRecordset
Dim objClone

Set objConnection = CreateObject("ADODB.Connection") 
Set objRecordset = CreateObject("ADODB.Recordset")

objConnection.Open _
        "Provider= Microsoft.Jet.OLEDB.4.0; " & _
            "Data Source=C:\Scripts\Test.mdb"

objRecordset.Open "Hardware", objConnection, adOpenKeyset, _
    adLockOptimistic, adCmdTableDirect

Set objClone = objRecordset.Clone

Do Until objClone.EOF
    Wscript.Echo objClone.Fields("Device").Value
    objClone.MoveNext
Loop

objClone.Close