Solved

ADO Recordset

Posted on 2002-07-24
6
213 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

749 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