ADO 2.7 Samples

AbsolutePosition and CursorLocation Properties Example (VB)

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.

'BeginAbsolutePositionVB

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string
    
Public Sub AbsolutePositionX()

    'recordset and connection variables
Dim rstEmployees As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQL As String
    'record variables
Dim strMessage As String
    
    'Open connection
    Set Cnxn = New ADODB.Connection
    strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=;"
    Cnxn.Open strCnxn

   strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
   ' Open Employee recordset with
   ' Client-side cursor to enable AbsolutePosition property
   Set rstEmployees = New ADODB.Recordset
   strSQL = "employee"
   rstEmployees.Open strSQL, strCnxn, adUseClient, adLockReadOnly, 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

    ' clean up
   rstEmployees.Close
   Cnxn.Close
   Set rstEmployees = Nothing
   Set Cnxn = Nothing

End Sub
'EndAbsolutePositionVB

See Also

AbsolutePosition Property | CursorLocation Property | Recordset Object

© 1998-2001 Microsoft Corporation. All rights reserved.