Didplay Random Record

  • Thread starter Thread starter Genius Maximus
  • Start date Start date
G

Genius Maximus

I have a table in Access 2000.

I want to display a random record from this table, or better: 5 random
records.

Is this possible with a query?

Thanks
LS - Brussels
 
Assuming your table has a primary key named "ID":

1. Create a query into your table.

2. Type this into a fresh column in the Field row:
Rnd([ID])

3. Open the Properties box (View menu), and in the Properties of the query
(not those of a field), enter the number of random records you want beside
the Top Values property.

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

The Rancomize is necessary each time you restart Access. Otherwise you will
get the same sequence of numbers generated.

The Rnd() function does not actually do anything with the autonumber field,
but if you do not pass in a value that is constantly changing, the query
optimizer realises that it does not have to call the function each time.
 
Back
Top