Random Sort in Access Query

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Hi,

How do I go about writing a query which randomly sorts the records in a
table ? Thanks.
 
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.
 
Search the Microsoft Knowledge Base
(http://support.microsoft.com/default.aspx?scid=FH;EN-US;KBHOWTO) for the word "random" (without
the quotes) and Access as the selected product. The second hit, for KB # 208855, is probably
what you are looking for.

Tom
______________________________________


Hi,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top