Absolute Position Percent Position

The AbsolutePosition and PercentPosition methods allow you to move the cursor to a specific row in the recordset. For example, if you wanted to move to the 127th row, you could issue the following method call:

rst.AbsolutePosition = 127

Similarly, if you wanted to move to (roughly) half-way through the recordset, you could issue this:

rst.PercentPosition = 50

Because you can also use these methods to determine where you are in the recordset, we usually use AbsolutePosition to determine if our recordset has any records in it.

Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset) If rst.AbsolutePosition > -1 Then

'The recordset contains records


'It does not End If

You see if AbsolutePosition returns -1, its position is undetermined. You can't determine the cursor position of an empty recordset. But if the recordset contains records, its position is determinable, and therefore, must be greater than -1. If AbsolutePosition = 0, you must be located at the first row of the recordset.

AbsolutePosition does not equate to a row number, and although it does return the cursor's current position in the recordset, that position can change as you add or delete rows, or change your filtering and sorting. You can't use AbsolutePosition with table-type recordsets, and ForwardOnly recordsets don't support either AbsolutePosition or PercentPosition.

0 0

Post a comment