Random Sort in Access Query

A

Adrian

Hi,

How do I go about writing a query which randomly sorts the records in a
table ? Thanks.
 
A

Allen Browne

Adrian said:
How do I go about writing a query which randomly sorts the records in a
table ? Thanks.

Assuming your table has an autonumber field named "ID":

1. Type this into a fresh column of Field row in query design:
Rnd([ID])

2. In the Sorting row under this calculated field, choose:
Ascending

3. Open the Immediate window (Ctrl+G) and enter:
Randomize

The Rnd() function does not do anything with the primary key value, but if
you do not pass in a number that changes on each row the query optimizer
does not bother calling the function again for every row.

The Randomize must be issued once in each session (e.g. in your
initialization code), or you will end up with repeatable results.
 
Top