Sorting Order Changes from Running Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm getting a strange result - data in a table is sorted before its read in
the VBA macro, but comes out in a different order. Anyway to maintain the
sort order?

More Details:
I read a table generated by a query into a recordset using the following code:

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("myQuery")

The table is sorted in the "myQuery" .

Then we read the recordset one record at a time and output the record:
rst.MoveFirst
Do Until rst.EOF
Call OutputRec(dbs, rst, outTable) 'Sub that executes sql insert
statement
rst.MoveNext
Loop

The output table is NOT in the same order as input data from myQuery.

Is there any way to make Access mainatain the sort order? Maybe its me, but
its crazy that the order isn't maintained in such a simple process.

Thank you,
Mark
 
Mark said:
I'm getting a strange result - data in a table is sorted before its read in
the VBA macro, but comes out in a different order. Anyway to maintain the
sort order?

More Details:
I read a table generated by a query into a recordset using the following code:

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("myQuery")

The table is sorted in the "myQuery" .

Then we read the recordset one record at a time and output the record:
rst.MoveFirst
Do Until rst.EOF
Call OutputRec(dbs, rst, outTable) 'Sub that executes sql insert
statement
rst.MoveNext
Loop

The output table is NOT in the same order as input data from myQuery.

Is there any way to make Access mainatain the sort order? Maybe its me, but
its crazy that the order isn't maintained in such a simple process.


You're not crazy, just suffereing from a misperception ;-)

Tables are not sorted and if you use a table's sheet view,
as it sounds like you are, they will appear in whatever
order Access/Jet finds convenient. If you want to view the
records in a particular order, you must use a query where
you can specify how you want the records to be sorted.
 
Thanks for setting me straight - I'm old school, record in and record out
won't change until I say so!!! I better get to school!!!
 
Back
Top