PercentPosition Property Example

This example uses the PercentPosition property to show the position of the current record pointer relative to the beginning of the Recordset.

Sub PercentPositionX()

   Dim dbsNorthwind As Database
   Dim rstProducts As Recordset
   Dim strFind As String
   Dim strMessage As String

   Set dbsNorthwind = OpenDatabase("Northwind.mdb")
   ' PercentPosition only works with dynasets or snapshots.
   Set rstProducts = dbsNorthwind.OpenRecordset( _
      "SELECT ProductName FROM Products " & _
      "ORDER BY ProductName", dbOpenSnapshot)

   With rstProducts
      ' Populate the Recordset.
      .MoveLast
      .MoveFirst

      Do While True
         ' Show current record information and ask user
         ' for input.
         strMessage = "Product: " & !ProductName & vbCr & _
            "The record pointer is " & _
            Format(.PercentPosition, "##0.0") & _
            "% from the " & vbCr & _
            "beginning of the Recordset." & vbCr & _
            "Please enter a character search string " & _
            "for a product name."
         strFind = Trim(InputBox(strMessage))
         If strFind = "" Then Exit Do

         ' Try to find a record matching the search string.
         .FindFirst "ProductName >= '" & strFind & "'"
         If .NoMatch Then .MoveLast
      Loop

      .Close
   End With

   dbsNorthwind.Close

End Sub