DAO openrecordset question 
Author Message
 DAO openrecordset question

Tony,
Any "order" you set when viewing a table in the database container is just a
view.

To order your data use an Order By clause in your sql:

 rcdMyTbl = mydb.openrecordset("SELECT * FROM myTable ORDER BY
myTable.ORDER")

The default order is ascending but you can have decending also:

 rcdMyTbl = mydb.openrecordset("SELECT * FROM myTable ORDER BY myTable.ORDER
ASC")
 rcdMyTbl = mydb.openrecordset("SELECT * FROM myTable ORDER BY myTable.ORDER
DESC")

Steve


Quote:
> Posted this in error under formscoding, so repost here as
> most relevant forum,

> Hello,

> When using VB rcdMyTbl = mydb.openrecordset("myTable")
> method followed by rcdMyTbl.movefirst I find that the
> table is Ordered by the underlying tables Autonumber field
> as opposed to 'OrdSupdate' Ascending Table OrderBy Order
> (does that make sense?) which screws up the calculation
> I'm trying to execute.

> How can I order the data correctly?
> .



Sun, 15 May 2005 00:52:18 GMT  
 DAO openrecordset question
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"

Quote:
>-----Original Message-----
>Posted this in error under formscoding, so repost here as
>most relevant forum,

>Hello,

>When using VB rcdMyTbl = mydb.openrecordset("myTable")
>method followed by rcdMyTbl.movefirst I find that the
>table is Ordered by the underlying tables Autonumber
field
>as opposed to 'OrdSupdate' Ascending Table OrderBy Order
>(does that make sense?) which screws up the calculation
>I'm trying to execute.

>How can I order the data correctly?
>..

>.



Sun, 15 May 2005 02:28:38 GMT  
 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.<<


Sun, 15 May 2005 06:05:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Type mismatch on openrecordset statement in DAO

2. OpenRecordset/DAO problem

3. db.OpenRecordset - Help using DAO cnn

4. OpenRecordset with DAO/ODBC

5. OpenRecordset in VB4 with DAO

6. DAO 3.51 to DAO 3.6 NULLs question

7. n00b question - How to use DAO

8. DAO with SQL question...

9. Newbie Questions About DAO Queries to SQL Server

10. dao to ado question

11. DAO question

12. DAO Recordset Question

 

 
Powered by phpBB® Forum Software