---
title: "Move Record Pointer of Recordset 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:
- "MoveLast method [ADO], VBScript example"
- "MoveNext method [ADO], VBScript example"
- "MovePrevious method [ADO], VBScript example"
- "MoveFirst method [ADO], VBScript example"
ms.assetid: 911aa1dd-2786-4f34-992c-bb2fbdabcbdf
author: MightyPen
ms.author: genemi
---
# MoveFirst, MoveLast, MoveNext, and MovePrevious Methods Example (VBScript)
This example uses the [MoveFirst](../../../ado/reference/ado-api/movefirst-movelast-movenext-and-moveprevious-methods-ado.md), [MoveLast](../../../ado/reference/ado-api/movefirst-movelast-movenext-and-moveprevious-methods-ado.md), [MoveNext](../../../ado/reference/ado-api/movefirst-movelast-movenext-and-moveprevious-methods-ado.md), and [MovePrevious](../../../ado/reference/ado-api/movefirst-movelast-movenext-and-moveprevious-methods-ado.md) methods to move the record pointer of a [Recordset](../../../ado/reference/ado-api/recordset-object-ado.md) based on the supplied command.
Cut and paste the following code into Notepad or another text editor, and save it as **MoveFirstVBS.asp**. You can view the result in any browser.
```
<%@ Language=VBScript %>
<%' use this meta tag instead of adovbs.inc%>
ADO MoveNext, MovePrevious, MoveLast, MoveFirst Methods
ADO MoveNext, MovePrevious
MoveLast & MoveFirst Methods
<% ' to integrate/test this code replace the
' Data Source value in the Connection string%>
<%
' connection and recordset variables
Dim Cnxn, strCnxn
Dim rsEmployees, strSQLEmployees
' 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 rsEmployees = Server.CreateObject("ADODB.Recordset")
strSQLEmployees = "Employees"
rsEmployees.ActiveConnection = Cnxn
rsEmployees.CursorLocation = adUseClient
rsEmployees.CursorType = adOpenKeyset
rsEmployees.LockType = adLockOptimistic
rsEmployees.Source = strSQLEmployees
rsEmployees.Open
rsEmployees.MoveFirst
If Not IsEmpty(Request.Form("MoveAction")) Then
strAction = Request.Form("MoveAction")
varPosition = Request.Form("Position")
rsEmployees.AbsolutePosition = varPosition
Select Case strAction
Case "MoveNext"
rsEmployees.MoveNext
If rsEmployees.EOF Then
rsEmployees.MoveLast
strMessage = "Can't move beyond the last record."
End If
Case "MovePrev"
rsEmployees.MovePrevious
If rsEmployees.BOF Then
rsEmployees.MoveFirst
strMessage = "Can't move beyond the first record."
End If
Case "MoveLast"
rsEmployees.MoveLast
Case "MoveFirst"
rsEmployees.MoveFirst
End Select
End If
%>
Record Number <%=rsEmployees.AbsolutePosition%> of <%=rsEmployees.RecordCount%>
| Name |
Hire Date |
| <%= rsEmployees("LastName") & ", " %>
<%= rsEmployees("FirstName") & " " %> |
<%= rsEmployees("HireDate")%> |
| <%=strMessage%> |
<%
' clean up
If rsEmployees.State = adStateOpen then
rsEmployees.Close
End If
If Cnxn.State = adStateOpen then
Cnxn.Close
End If
%>
```
## See Also
[MoveFirst, MoveLast, MoveNext, and MovePrevious Methods (ADO)](../../../ado/reference/ado-api/movefirst-movelast-movenext-and-moveprevious-methods-ado.md)
[Recordset Object (ADO)](../../../ado/reference/ado-api/recordset-object-ado.md)