PercentPosition Property Example (MDB)
The following example expresses the current position of a record in a recordset as a percent, then displays it in a message box:
Sub PercentOfRecords()
Dim dbs As Database, rst As Recordset
Dim strInput As String, strSQL As String
strSQL = "SELECT * FROM Products ORDER BY ProductName;"
' Return reference to current database.
Set dbs = CurrentDb
' Open dynaset-type Recordset object.
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
' Move to end of recordset.
rst.MoveLast
' Return to start of recordset.
rst.MoveFirst
' Prompt user to input name of product.
strInput = InputBox("Please enter the full product name.")
' Find first occurrence.
rst.FindFirst "ProductName = '" & strInput & "'"
' Display current position as a percent.
MsgBox("The current position in the Recordset is " _
& rst.PercentPosition & "%.")
rst.Close
Set dbs = Nothing
End Sub