ADO Samples

Clone Method Example (VBScript)

This example uses the Clone method to create copies of a Recordset 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. Use Find to locate the file Adovbs.inc and place it in the directory you plan to use. Cut and paste the following code to Notepad or another text editor and save it as Clone.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.

<!-- BeginCloneVBS -->
<% Language = VBScript %>
<!-- #Include file="ADOVBS.INC" -->
<HTML>
<HEAD>
<TITLE>ADO Clone Method</TITLE>
</HEAD>

<BODY>

<H3>ADO Clone Method</H3>
<% 
   ' ADO Connection Object used to Create recordset
   src = "\program files\microsoft office\office\samples\northwind.mdb"
   sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src

   'Create and Open Connection Object
   Set OBJdbConn = Server.CreateObject("ADODB.Connection") 
   OBJdbConn.Open  sConnStr
   'Create and open Recordset object
   Set RsCustomerList = Server.CreateObject("ADODB.Recordset")
   RsCustomerList.ActiveConnection = OBJdbConn
   RsCustomerList.CursorType = adOpenKeyset
   RsCustomerList.LockType = adLockOptimistic
   RsCustomerList.Source = "Customers"
   RsCustomerList.Open

   ' Loop through Customers Table, adding 1 to the Counter variable each pass
   Set MyRecordset = RSCustomerList.Clone
   Counter = 0
   Do Until MyRecordset.EOF
      Counter = Counter + 1
      MyRecordset.MoveNext
   Loop
%>

<!-- Display Results -->
<H3>There Are <%=Counter %> Records in the Customers Table</H3>
<BR><HR>
<H4>Location of DSN Datbase</H4>

<%
   ' Show location of DSN data source
   Response.Write(OBJdbConn)
%>
</BODY>
</HTML>
<!-- EndCloneVBS -->

See Also

Clone Method | Recordset Object