Solved

Sorting with ADO

Posted on 2002-07-17
3
237 Views
Last Modified: 2007-11-27
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"""
   Else
        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
0
Comment
Question by:lmred
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
priya_pbk earned 50 total points
ID: 7159335
I think it should be "equal to sign"

strSortBy="id desc"
rs.Sort =strSortBy  
0
 
LVL 1

Author Comment

by:lmred
ID: 7159354
I cannot believe that I missed that! I've looked at this a million times and never even noticed that. Thanks so much!

Lisa
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7159360
Glad to be of some help!

-priya
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question