Still trying to figure out how to sort descending with a dao recordset using the control, not sql.. can anyone help?
Thanks,
Thai
Printable View
Still trying to figure out how to sort descending with a dao recordset using the control, not sql.. can anyone help?
Thanks,
Thai
Why don't you use SQL statement in your RecordSource statement? :confused:
What type of control you're using? Data Control?
Maybe you can do it like this:
Over here i use the Biblio.mdb database as my sample code.
I assume that you have add a DBGrid control and Data control in your form layout, and set the DBGrid DataSource to Data control.
Code:Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\Biblio.mdb"
'For Sorting the record base on the PubID Desc
Data1.RecordSource = "SELECT * FROM Publishers Order By PubID DESC;"
or
'For Sorting the record base on the PubID Asc
Data1.RecordSource = "SELECT * FROM Publishers Order By PubID ASC;"
Data1.Refresh
DBGrid1.Refresh
End Sub
I don't want to use SQL because the recordset has already been opened and I want to sort then refresh and have the recordset be sorted descending. That is why I specified in my previous post that I didn't need an sql example. I already know how to do it that way, I just need an example of how to do it with dao's recordset sort/attribute properties.
Thanks,
Thai
Hi Thai how about the Clone recordset? But this may not be the best solution. :)
Code:Private Sub Form_Load()
Dim OrgDb As DAO.Database
Dim OrgRs As DAO.Recordset
Dim CloneRs As DAO.Recordset
Set OrgDb = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\Biblio.mdb", False, False)
Set OrgRs = OrgDb.OpenRecordset("SELECT * FROM Publishers ORDER BY PubID ASC;", dbOpenSnapshot)
Set CloneRs = OrgRs.Clone
CloneRs.MoveLast
While Not CloneRs.BOF
Debug.Print CloneRs.Fields(0)
CloneRs.MovePrevious
Wend
CloneRs.Close
Set CloneRs = Nothing