|
-
Jun 8th, 2000, 01:03 AM
#1
Thread Starter
Addicted Member
Can someone show me an example of using the DAO recordset object to sort DESCENDING?
Thanks,
Thai
-
Jun 8th, 2000, 07:02 AM
#2
Hyperactive Member
Since you don't say how you're setting up DAO, I'll start with a MS example at
http://support.microsoft.com/support.../Q147/8/82.asp
Assuming you follow from the example, then to sort the resultset use something like this (note the bold text):
Code:
StrSQL = "Select * from titles where title like 'a*' ORDER BY [sort_field_name] DESC;"
Hope this helps.
-
Jun 8th, 2000, 08:55 AM
#3
Thread Starter
Addicted Member
Sorry I should have been more clear... I need an example of how to sort the recordset in descending order using the dao control's sort and its attributes. Is there a way to sort descending with the control not using SQL? I read about it on MS's web site but they gave no examples, they just said it was possible. Please help if you can..
Thanks,
Thai
-
Jun 8th, 2000, 09:22 AM
#4
Hyperactive Member
I'm a bit of an SQL-bonehead-snob, so I tend to think it's mo' betta to create a Recordset with an SQL statement. Tell me which control you're using, and I'll try to help.
-
Jun 8th, 2000, 09:54 AM
#5
Thread Starter
Addicted Member
k.. I am using two controsl.. the db grid and the dao control. I set the property of the data and recordset in the dao control so it has the recordset.. then i set the db grid's datasource to Data1 (which is the dao control).
So now I can manipulate the recordset in code by using data1.recordset yadda yadda and the changes will appear in the grid. How do I make Data1 sort DESCENDING on a field I want? It should automatically show the changes in the grid when the sort happens. That is my goal Thanks
Thai
-
Jun 8th, 2000, 10:53 AM
#6
Hyperactive Member
otay, if I understand you correctly (which is a big "IF" as I'm being thick-skulled tonight), this example is stolen directly from the DAO 3.5 help file, with a minor DESC modification...
Code:
This example demonstrates the Sort property by changing its value and creating a new Recordset. The SortOutput function is required for this procedure to run.
Sub SortX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim rstSortEmployees As Recordset
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", dbOpenDynaset)
With rstEmployees
SortOutput "Original Recordset:", rstEmployees
' "magic" happens here...
.Sort = "LastName DESC, FirstName"
' Print report showing Sort property and record order.
SortOutput "Recordset after changing Sort property:", rstEmployees
' Open new Recordset from current one.
Set rstSortEmployees = .OpenRecordset
' Print report showing Sort property and record order.
SortOutput "New Recordset:", rstSortEmployees
rstSortEmployees.Close
.Close
End With
dbsNorthwind.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
Your remaining task will be to Data1.Refresh appropriately...
-
Jun 8th, 2000, 10:58 AM
#7
Thread Starter
Addicted Member
Thanks for the help!
Thai
-
Jun 8th, 2000, 04:13 PM
#8
PowerPoster
Clone recordset
How abt my solution? does it what you looking for?
Thread
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
|