Solved

ADO Recordset

Posted on 2002-07-24
6
205 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
Comment Utility
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
Comment Utility
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
Comment Utility


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

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

'you missed the equal to..

-priya
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Expert Comment

by:wensinkg
Comment Utility
Absolutely correct.  Sorry.
0
 
LVL 5

Accepted Solution

by:
bob_online earned 100 total points
Comment Utility
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
Comment Utility
strsql = "select d,staffid, rollid, staffname from [tablea]

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


order by staffname
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

743 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

17 Experts available now in Live!

Get 1:1 Help Now