Solved

Sorting with ADO

Posted on 2002-07-17
3
234 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now