Solved

ADO Recordset

Posted on 2002-07-24
6
208 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
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.

 

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

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

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

919 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

12 Experts available now in Live!

Get 1:1 Help Now