Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP On Sorting Recordsets !!!!

Status
Not open for further replies.

TrekFan

Programmer
Apr 23, 2003
25
CR

Hi there,

I have a recordset with data (yes with data ! :) ) .. and I need to be able to sort it by different columns (without requeryng the db). I though the “sort” property of the ADO 2.5 recordset would help me, but here is where it gets tricky: in case of “date columns” or “money fields” the existing SQL Server 2000 store procedures return this data formatted and converted to string …. So if I use a regular

Recordset.Sort “ColumnName” Order


I get really weird results … so I need to do some manipulation to strip out the characters to be able to sort them correctly. If I could do something like :

Recordset.Sort SubString(ColumnName,1,2) + SubString(ColumnName,4,2) “Order”



Any suggestions would be greatly welcome !!!!!!!!!


Thanks

TF
 

The easiest would be to convert the columns back into the correct format for your sort. Here's a brute force method to place items in a local recordset and sort accordingly; you'll have to adapt it to your specific needs:

Private Sub Form_Load()
Dim rs As New ADODB.Recordset

rs.Fields.Append "d", adInteger
rs.Fields.Append "m", adInteger
rs.Fields.Append "y", adInteger

rs.Open

For i = 1 To 15
rs.AddNew
rs("d") = i
rs("m") = 4
rs("y") = 3
rs.Update
Next
rs.MoveFirst
rs.Sort = "d asc" 'ascending
rs.MoveFirst
While Not rs.EOF
Debug.Print Format(rs("m"), "00") & "/" & Format(rs("d"), "00") & "/" & Format(rs("y"), "00")
rs.MoveNext
Wend
rs.Sort = "m asc, d desc" ' descending
rs.MoveFirst
While Not rs.EOF
Debug.Print Format(rs("m"), "00") & "/" & Format(rs("d"), "00") & "/" & Format(rs("y"), "00")
rs.MoveNext
Wend
rs.Close
set rs = nothing
End Sub





Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top