Sorting with ADO

I have executed a stored procedure and have received the results. I am using ADO 2.6. I want to sort the results using the sort property, but for some reason I keep getting 'invalid use of property'. Can somebody help me figure out why I am getting this error? The syntax looks fine. Here is my code:

Public Function Sort(cndatabase As ADODB.Connection, strDataSource As String, strSortBy As String, Optional bolSortAsc As Boolean)

    '***this function sorts current records based on the field and sort order passed into the function
    '***if the ascending flag is not passed in, it is automatically false
    Dim rs As ADODB.Recordset, fld As ADODB.Field
    Set rs = OpenRecordset(cndatabase, strDataSource, rs)
   If bolSortAsc Then
        rs.Sort """" & strSortBy & " asc"""
        rs.Sort """" & strSortBy & " desc"""
   End If
End Function

Private Function OpenRecordset(cndatabase As ADODB.Connection, strDataSource As String, rsNewRecordset As ADODB.Recordset, Optional lngMaxRecords As Long) As ADODB.Recordset
    '***this function opens a recordset
    Set rsNewRecordset = New ADODB.Recordset
    rsNewRecordset.CursorLocation = adUseClient
    '***determine the maximum # of records to return from the query
    '***this replaces 'top'
    If lngMaxRecords > 0 Then
        rsNewRecordset.MaxRecords = lngMaxRecords
    End If

    rsNewRecordset.Open strDataSource, cndatabase, adOpenStatic
    Set rsNewRecordset.ActiveConnection = Nothing
    Set OpenRecordset = rsNewRecordset
End Function
Who is Participating?
priya_pbkConnect With a Mentor Commented:
I think it should be "equal to sign"

strSortBy="id desc"
rs.Sort =strSortBy  
lmredAuthor Commented:
I cannot believe that I missed that! I've looked at this a million times and never even noticed that. Thanks so much!

Glad to be of some help!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.