|
-
Oct 23rd, 2002, 03:31 PM
#1
Thread Starter
Hyperactive Member
Sort Recordset
Hello everyone how are you?
I wonder is anybody had a Sort sample to sort recordset in a database? I need to build a program to sort my recordset in diferent orders.
Thank you, and have nice day!
-
Oct 23rd, 2002, 03:33 PM
#2
PowerPoster
"Select F1,F2,F3 from Table1 where F2=5 Order By F1"
-
Oct 23rd, 2002, 03:35 PM
#3
Thread Starter
Hyperactive Member
May be you misunderstand me I need to build a code in visual basic in order that the user can use it any time
-
Oct 23rd, 2002, 03:43 PM
#4
PowerPoster
So, I just showed how tio do that. The only difference will be that you will need to replace F1, etc , Table1 with your real field/table name and open recordset using your SQL statement:
rstMyRecordset.Open strMySQL, ...
-
Oct 23rd, 2002, 03:44 PM
#5
PowerPoster
Well
You can display the data in a grid or listview, and let the user sort the data at will...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Oct 23rd, 2002, 10:12 PM
#6
Addicted Member
select statement order by would do
-
Oct 24th, 2002, 02:03 AM
#7
Frenzied Member
if you insist on sorting a RECORDSET... then
VB Code:
MyRec.Recordsets(0).Sort="MyField"
But
1. It's slow
2. It has a lot of limitations and considerations to be kept in view.. (like doesn't work on Forward-only recordset)
-
Oct 24th, 2002, 07:26 AM
#8
PowerPoster
What the heck are talking about?! You just have to send SQL statement with Order By clause as I and SC@RF@C3 pointed out.
-
Oct 24th, 2002, 10:18 AM
#9
I agree with moinkhan there is no need to make another trip to the db when the recordset object has a sort method.
-
Oct 24th, 2002, 10:21 AM
#10
Originally posted by moinkhan
if you insist on sorting a RECORDSET... then
VB Code:
MyRec.Recordsets(0).Sort="MyField"
But
1. It's slow
2. It has a lot of limitations and considerations to be kept in view.. (like doesn't work on Forward-only recordset)
3. Can't sort on more than one field.
-
Oct 24th, 2002, 10:29 AM
#11
PowerPoster
I agree with moinkhan there is no need to make another trip to the db when the recordset object has a sort method.
Sure, but it only works on 1 (one) field. Using Order By clause will give you flexibilty of sorting on the multiple fields and it's much faster anyway.
-
Oct 24th, 2002, 11:18 AM
#12
-
Oct 24th, 2002, 12:13 PM
#13
Thread Starter
Hyperactive Member
I got this example from microsoft, bu this is not working, it does not replace my fisical table.
Dim dbs As Database
Dim rs As Recordset
Dim rsSort As Recordset
Set dbs = OpenDatabase("C:\Address\Address.mdb")
Set rs = dbs.OpenRecordset("A", dbOpenDynaset)
With rs
SortOutput "Original Recordset:", rs
.Sort = "LastName, FirstName"
' Print report showing Sort property and record order.
SortOutput _
"Recordset after changing Sort property:", rs
' Open new Recordset from current one.
Set rsSort = .OpenRecordset
Set rs = rstSort
' Print report showing Sort property and record order.
SortOutput "New Recordset:", rsSort
rsSort.Close
.Close
End With
dbs.Close
End Sub
Function SortOutput(strTemp As String, rstTemp As Recordset)
With rstTemp
Debug.Print strTemp
Debug.Print " Sort = " & _
IIf(.Sort <> "", .Sort, "[Empty]")
.MoveFirst
' Enumerate Recordset.
Do While Not .EOF
Debug.Print " " & !LastName & _
", " & !FirstName
.MoveNext
Loop
End With
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|