Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recordset.Sort method not sorting

First time I've used .Sort but from Googling the following should work, but the debug print output is not sorted.

Function SortByYear(ByVal z As DAO.Recordset) As String
 Dim mySortedRS As DAO.Recordset
 z.Sort = "Year"
 Set mySortedRS = z
    Do
        Debug.Print mySortedRS!Year
        mySortedRS.MoveNext
    Loop Until mySortedRS.EOF
Set mySortedRS = Nothing
End Function
like image 995
Kirk Avatar asked May 16 '26 12:05

Kirk


1 Answers

When you

Set mySortedRS = z

you are not creating a new Recordset object, you are simply creating a new variable that points to the existing Recordset object. To create a new (sorted) Recordset you need to use

Set mySortedRS = z.OpenRecordset

For more information, see

Recordset.Sort Property (DAO)

like image 141
Gord Thompson Avatar answered May 19 '26 02:05

Gord Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!