Min, Max Functions Example (DAO)

Microsoft Jet SQL Reference

Min, Max Functions Example

This example uses the Orders table to return the lowest and highest freight charges for orders shipped to the United Kingdom.

This example calls the EnumFields procedure, which you can find in the SELECT statement example.

Sub MinMaxX()

    Dim dbs As Database, rst As Recordset

    ' Modify this line to include the path to Northwind

    ' on your computer.

    Set dbs = OpenDatabase("Northwind.mdb")

    

    ' Return the lowest and highest freight charges for

    ' orders shipped to the United Kingdom.

    Set rst = dbs.OpenRecordset("SELECT " _

        & "Min(Freight) AS [Low Freight], " _

        & "Max(Freight)AS [High Freight] " _

        & "FROM Orders WHERE ShipCountry = 'UK';")

    

    ' Populate the Recordset.

    rst.MoveLast

    

    ' Call EnumFields to print the contents of the

    ' Recordset. Pass the Recordset object and desired

    ' field width.

    EnumFields rst, 12

    dbs.Close

End Sub