Example
Sorting Recordsets.
The following example uses DGrid for DAO.
Record sorting code snippet.
The fastest way to sort records in a DGrid control is to simply reload the recordset in the desired sort order as illustrated below. The code snippet assumes an open database named "db", an open recordset named "rs" and a DGrid control named "DGrid1" sited on the form.
Screen.MousePointer = 11
'Unload the grid and close the current recordset
DGrid1.UnloadRecords
rs.Close
Set rs = Nothing
'Open a new recordset in the desired sort order
'and populate the grid
Set rs = db.OpenRecordset("Select * From YourTable Order By Yourfield")
DGrid1.LoadRecords rs
DGrid1.Refresh
Screen.MousePointer = 0