
DAO openrecordset question
Quote:
> You can add the ORDER BY clause to your SELECT statement.
> Or, try using the .Sort property for the recordset after
> you have opened it. Look in the help file for the
> specifics of this property. This allows you to re-order
> the recordset at any time you need to.
> example:
> rcdMyTbl = mydb.openrecordset("myTable")
> rcdMyTbl.Sort = "OrdSupdate"
Good solution, but you left out the most important part. You must open another
recordset from the first after setting the .Sort property, or you won't get the
benefit from the sort:
'********EXAMPLE START
'You must declare a second recordset to get the sorted records
Dim rcdMyTblSorted As Recordset
rcdMyTbl = mydb.openrecordset("myTable")
rcdMyTbl.Sort = "OrdSupdate"
'Now, open the second recordset
rcdMyTblSorted.OpenRecordset()
'Now, work with this second recordset. Just remember to close all your
recordsets
' (in the reverse order of opening them) and set the recordsets to Nothing.
' If you set a "db = CurrentDb()", set that to Nothing, as well - if you
created a "db"
' as in "Set db = DBEngine ..." then close it before setting it to nothing.
'********EXAMPLE END
--
Bruce M. Thompson, Microsoft Access MVP
Quote:
>>No Email, Please. Keep all communications
within the newsgroups so that all might benefit.<<