--- title: "Clone Method Example (VBScript) | Microsoft Docs" ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.custom: "" ms.date: "01/19/2017" ms.reviewer: "" ms.topic: conceptual dev_langs: - "VB" helpviewer_keywords: - "Clone method [ADO], VBScript example" ms.assetid: 36b96e3d-8cb0-4b79-bd93-ea5e0eb5679f author: MightyPen ms.author: genemi --- # Clone Method Example (VBScript) This example uses the [Clone](../../../ado/reference/ado-api/clone-method-ado.md) method to create copies of a [Recordset](../../../ado/reference/ado-api/recordset-object-ado.md) and then lets the user position the record pointer of each copy independently. Use the following example in an Active Server Page (ASP). This example uses the **Northwind** database distributed with Microsoft Access. Cut and paste the following code to Notepad or another text editor and save it as CloneVBS.asp. You can view the result in any client browser. To exercise the example, change the line `RsCustomerList.Source = "Customers"` to `RsCustomerList.Source = "Products"` to count a larger table. ``` <% Language = VBScript %> <%' use this meta tag instead of adovbs.inc%> ADO Clone Method

ADO Clone Method


<% ' to integrate/test this code replace the ' Data Source value in the Connection string%> <% ' connection and recordset variables Dim Cnxn, strCnxn Dim rsCustomers, strSQLCustomers Dim rsFirst, rsLast, rsCount Dim rsClone Dim CloneFirst, CloneLast, CloneCount ' open connection Set Cnxn = Server.CreateObject("ADODB.Connection") strCnxn = "Provider='sqloledb';Data Source=" & _ Request.ServerVariables("SERVER_NAME") & ";" & _ "Integrated Security='SSPI';Initial Catalog='Northwind';" Cnxn.Open strCnxn ' create and open Recordset using object refs Set rsCustomers = Server.CreateObject("ADODB.Recordset") strSQLCustomers = "Customers" rsCustomers.ActiveConnection = Cnxn rsCustomers.CursorLocation = adUseClient rsCustomers.CursorType = adOpenKeyset rsCustomers.LockType = adLockOptimistic rsCustomers.Source = strSQLCustomers rsCustomers.Open rsCustomers.MoveFirst rsCount = rsCustomers.RecordCount rsFirst = rsCustomers("CompanyName") rsCustomers.MoveLast rsLast = rsCustomers("CompanyName") ' create clone Set rsClone = rsCustomers.Clone rsClone.MoveFirst CloneCount = rsClone.RecordCount CloneFirst = rsClone("CompanyName") rsClone.MoveLast CloneLast = rsClone("CompanyName") %>

There Are <%=rsCount%> Records in the original recordset

The first record is <%=rsFirst%> and the last record is <%=rsLast%>



There Are <%=CloneCount%> Records in the original recordset

The first record is <%=CloneFirst%> and the last record is <%=CloneLast%>



Location of OLEDB Database

<% ' Show location of DSN data source Response.Write(Cnxn) ' Clean up If rsCustomers.State = adStateOpen then rsCustomers.Close End If If rsClone.State = adStateOpen then rsClone.Close End If If Cnxn.State = adStateOpen then Cnxn.Close End If Set rsCustomers = Nothing Set rsClone = Nothing Set Cnxn = Nothing %> ``` ## See Also [Clone Method (ADO)](../../../ado/reference/ado-api/clone-method-ado.md) [Recordset Object (ADO)](../../../ado/reference/ado-api/recordset-object-ado.md)