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
| Parameter | Description |
| sFieldName | Name 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 SubThe 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
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |