Home > Language Reference > Classes > Recordset

Max Function

Returns the maximum value of a given field over the whole recordset.

Syntax

Public Function Max(ByRef sFieldName As String) As Variant

ParameterDescription
sFieldNameName of the field on which to perform the computation.

Remarks

The Max function computes the maximum value of the field specified by the sFieldName parameter over the whole recordset. If the recordset was opened using OpenRecordset, the computation is performed over the records that match the specified query. On the other hand, if the recordset was opened using OpenTable, the computation is perfomed over all the records in the table.

For example, the following code displays the maximum price of books by William Blake:

Private Sub Button1_Click()
  Dim db as New tblBooks

  db.OpenRecordset "Author='Blake'", hbModeOpenExisting+hbModeReadOnly
  MsgBox db.Max("Price")
  db.Close
End Sub

The cursor position is not modified by a call to this function, nor the value of the various fields of the current record, thus it can be used while enumerating records.

Note that this function can only operate on fields whose type is Byte, Integer, Long, Single, Double, Date, and String. If the sFieldName parameter specifies another type of field, a runtime error occurs. If the recordset does not contain any record, the returned value is Empty.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A