IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Stupid Access tricks.
Here's the deal: I have a table with a field called 'Random'. I put random numbers in that field and then sorted it by Random (using the Sort button while the table was open) to put it in a random order. I wanted to maintain this random order after another set of records is added to it. So I created another field called 'Order_Num'. I wrote a routine that just stepped through this table an putting an incrementing number in the Order_Num field. Here's the code:

Dim MyDB As Database
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Dim WorkData As Recordset
Set WorkData = CurrentDB.OpenRecordset("tblRandomIntervVisits")
Dim i As Integer
i = 1
WorkData.MoveFirst
Do Until WorkData.EOF
WorkData.Edit
WorkData!Order_Num = i
WorkData.Update
i = i + 1
WorkData.MoveNext
Loop

Problem is, when I go back and look at the table, it is not in the original random order (by Random) anymore. Somehow, when it brought the table into the recordset (WorkData) it imposed its own order on it and thus screwed up the original sorted order. None of the fields are Indexed. There appears to be no other order present, but it IS kinda separating them in blocks based on another field, Population (1/0). A block of 1's, a block of 0's, 1's, 0's, etc.

WTF?
New Please note.
I solved it by bringing the records in using an SQL statement and telling it to sort it by Random, but I want to know where whatever ordering system it is using is coming from.
New The default order in Access seems to be the row create date.
At least in my experience. YMMV
A stupid despot may constrain his slaves with iron chains; but a true politician binds them even more strongly by the chain of their own ideas;...despair and time eat away the bonds of iron and steel, but they are powerless against the habitual union of ideas, they can only tighten it still more; and on the soft fibres of the brain is founded the unshakable base of the soundest of Empires."

Jacques Servan, 1767
New SELECT FROM: ordering is undefined
Check your SQL standard. The ordering of data is not defined in a SELECT operation unless an ORDER BY is explicitly given. The order may be arbitrary. See Joe Celko's books for more data on this.
--
Karsten M. Self [link|mailto:kmself@ix.netcom.com|kmself@ix.netcom.com]
What part of "gestalt" don't you understand?
New True, but....
are you implying that Access follows SQL standards?
"Beware of bugs in the above code; I have only proved it correct, not tried it."
-- Donald Knuth
     Stupid Access tricks. - (acagle) - (4)
         Please note. - (acagle) - (1)
             The default order in Access seems to be the row create date. - (tseliot)
         SELECT FROM: ordering is undefined - (kmself) - (1)
             True, but.... - (wharris2)

Priorities, people. Jeez.
36 ms