Microsoft ActiveX Data ObjectsMicrosoft ActiveX Data Objects*
*Contents  *Index  *Topic Contents

AbsolutePosition and CursorLocation Properties Example

This example demonstrates how the AbsolutePosition property can track the progress of a loop that enumerates all the records of a Recordset. It uses the CursorLocation property to enable the AbsolutePosition property by setting the cursor to a client cursor.

Public Sub AbsolutePositionX()

	Dim rstEmployees As ADODB.Recordset
	Dim strCnn As String
	Dim strMessage As String

	' Open a recordset for the Employee table
	' using a client cursor.
	strCnn = "driver={SQL Server};server=srv;" & _
		"uid=sa;pwd=;database=pubs"
	Set rstEmployees = New ADODB.Recordset
	' Use client cursor to enable AbsolutePosition property.
	rstEmployees.CursorLocation = adUseClient
	rstEmployees.Open "employee", strCnn, , , adCmdTable
	
	' Enumerate Recordset.
	Do While Not rstEmployees.EOF
		' Display current record information.
		strMessage = "Employee: " & rstEmployees!lName & vbCr & _
			"(record " & rstEmployees.AbsolutePosition & _
			" of " & rstEmployees.RecordCount & ")"
		If MsgBox(strMessage, vbOKCancel) = vbCancel _
			Then Exit Do
		rstEmployees.MoveNext
	Loop

	rstEmployees.Close

End Sub

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.