ORDER BY Clause Example (DAO)

Microsoft Jet SQL Reference

ORDER BY Clause Example

The SQL statement shown in the following example uses the ORDER BY clause to sort records by last name in descending order (Z-A).

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

Sub OrderByX()

    Dim dbs As Database, rst As Recordset

    ' Modify this line to include the path to Northwind

    ' on your computer.

    Set dbs = OpenDatabase("Northwind.mdb")

    ' Select the last name and first name values from

    ' the Employees table, and sort them in descending

    ' order.

    Set rst = dbs.OpenRecordset("SELECT LastName, " _

        & "FirstName FROM Employees " _

        & "ORDER BY LastName DESC;")

    

    ' Populate the Recordset.

    rst.MoveLast

    

    ' Call EnumFields to print recordset contents.

    EnumFields rst, 12

    dbs.Close

End Sub