--- title: "Move 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: - "Move method, VBScript example" ms.assetid: 29ec4b95-8986-4970-943f-3da3ecb207a2 author: MightyPen ms.author: genemi --- # Move Method Example (VBScript) This example uses the [Move](../../../ado/reference/ado-api/move-method-ado.md) method to position the record pointer, based on user input. Use the following example in an Active Server Page (ASP). To view this fully functional example, you must either have the data source AdvWorks.mdb (installed with the SDK) located at C:\Program Files\Microsoft Platform SDK\Samples\DataAccess\Rds\RDSTest\advworks.mdb or edit the path in the example code to reflect the actual location of this file. This is a Microsoft Access database file. 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 **MoveVBS.asp**. You can view the result in any browser. Try entering a letter or noninteger to see the error handling work. ``` <%@ Language=VBScript %> <%' use this meta tag instead of adovbs.inc%> ADO Move Methods

ADO Move Methods

<% ' to integrate/test this code replace the ' Data Source value in the Connection string%> <% ' connection and recordset variables Dim Cnxn, strCnxn Dim rsCustomers, strSQLCustomers ' 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 'Check number of user moves this session and increment by entry Session("Clicks") = Session("Clicks") + Request.Form("MoveAmount") Clicks = Session("Clicks") ' Move to last known recordset position plus amount passed rsCustomers.Move CInt(Clicks) 'Error Handling If rsCustomers.EOF Then Session("Clicks") = rsCustomers.RecordCount Response.Write "This is the Last Record" rsCustomers.MoveLast ElseIf rsCustomers.BOF Then Session("Clicks") = 1 rsCustomers.MoveFirst Response.Write "This is the First Record" End If %>

Current Record Number is
<% If Session("Clicks") = 0 Then Session("Clicks") = 1 Response.Write(Session("Clicks") )%> of <%=rsCustomers.RecordCount%>


<% 'display%>
Company Name Contact Name City
<%= rsCustomers("CompanyName")%> <%= rsCustomers("ContactName")%> <%= rsCustomers("City")%>

Click Direction Arrows for Previous or Next Record

Click Move Amount to use Move Method
Enter Number of Records to Move + or -
<% ' clean up If rsCustomers.State = adStateOpen then rsCustomers.Close End If If Cnxn.State = adStateOpen then Cnxn.Close End If %> ``` ## See Also [Move Method (ADO)](../../../ado/reference/ado-api/move-method-ado.md) [Recordset Object (ADO)](../../../ado/reference/ado-api/recordset-object-ado.md)