ADO - Absolute Position
1. Purpose
AbsolutePosition tells you which record (by number) the record pointer is currently on — for example, 1st, 2nd, 3rd, etc.
2. Syntax
rs.AbsolutePosition
or to move to a specific record:
rs.AbsolutePosition = 5
3. Description
-
The first record in the
Recordsethas a position of 1. -
If the current position is before the first record,
AbsolutePositionreturns adPosBOF. -
If the position is after the last record, it returns adPosEOF.
-
You can use it to identify or return to a particular record.
4. Example
rs.Open "SELECT * FROM Employees", conn, adOpenStatic, adLockReadOnly
rs.MoveFirst
MsgBox "Current record position: " & rs.AbsolutePosition ' Shows 1
rs.MoveNext
MsgBox "Current record position: " & rs.AbsolutePosition ' Shows 2
' Move directly to 5th record
rs.AbsolutePosition = 5
MsgBox "Now on record: " & rs("EmployeeName")
5. Important Notes
-
AbsolutePositionstarts from 1, not 0. -
It is available only for Recordsets that support bookmarks (e.g.,
adOpenStatic,adOpenKeyset, oradOpenDynamic). -
It does not work with
adOpenForwardOnlycursor type. -
Useful when:
-
You want to display record numbers (e.g., “Record 3 of 10”).
-
You need to return to a specific record later.
-
6. Related Property
-
RecordCount→ tells you how many records are in the Recordset. -
Together, you can use:
MsgBox "Record " & rs.AbsolutePosition & " of " & rs.RecordCount