Solved

ADO Recordset

Posted on 2002-07-24
6
211 Views
Last Modified: 2013-11-26
OK I have a component which has a method which returns an

id
Staffid,
Roleid,

From this i can call another method to return the staff name using the staff id.

I would like to order the recordset by the staff name. Is there anyway this can be done?
0
Comment
Question by:mm_glebe
6 Comments
 

Expert Comment

by:wensinkg
ID: 7174034
You could structure the SQL statement to take that into account or you could use the Sort function of ADO.  Your statement would look like this:

SELECT ID, StaffID, RoleID from <TableNameHere> Order By StaffID

Or if you cannot do this for whatever reason use:

rs.Sort "StaffID ASC<Or DESC>"

Be aware that if you use the latter you must use a static, Client Side Cursor on your recordset.  I use this all of the time with disconnected recordsets so that I can change the order that information that appears in lists and combo boxes.  A disconnected recordset also conserves network resources.
0
 

Author Comment

by:mm_glebe
ID: 7174064
I can't amend the SQL statement (stored procedure) at this time.

I'm also aware of the sort method but this will only help for the id. I want ot sort on staffname, which is not in the original recordset.
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7174261


>>rs.Sort "StaffID ASC<Or DESC>"

that should be:
rs.Sort="StaffID ASC<Or DESC>"

'you missed the equal to..

-priya
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Expert Comment

by:wensinkg
ID: 7174539
Absolutely correct.  Sorry.
0
 
LVL 5

Accepted Solution

by:
bob_online earned 100 total points
ID: 7175132
If this is a read only recordset, you can

Disconnect the recordset (Set ActiveConnection = nothing)
Add a field to the fields collection or the recordset.

Loop through the recordset and for each record
  Run your process to get the staff name for each id
  set the value of your new field to the staff name

Sort on the new field.

The simple approach is, of course, to modify the original sql to return that value, but if that is not an option...
0
 
LVL 2

Expert Comment

by:mmcmillen
ID: 7176222
strsql = "select d,staffid, rollid, staffname from [tablea]

inner join [tableb] on [tablea].staffid = [tableb].staffid


order by staffname
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

825 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