Solved

Sorting with ADO

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

821 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