Solved

Sorting with ADO

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 74
using Access 8 58
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 40
Access Object Property from VBA Module in Excel 2010 2 27
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

932 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

9 Experts available now in Live!

Get 1:1 Help Now