ACC: Find N Records in Random OrderID: Q128874
|
Novice: Requires knowledge of the user interface on single-user computers.
This article shows you how to shuffle the records in a table in random
order. It also shows you how to get <n> records from a table at random
(where <n> is the number of records that you want). You can use this method
to make sure that the records will never be repeated.
To shuffle the records in a table, create a query based on that table and
all its necessary fields. Add a calculated field that contains the Rnd()
function with a positive integer variable parameter. Then, sort by this
calculated field. Every time you evaluate the query, the records will be
shuffled.
To get <n> records at random, set the query's TopValues property to
the number of records you want.
The Rnd() function requires a numeric argument to return a random number.
If the argument is greater than zero, the next random number in the
sequence is returned. Because of the way queries are optimized, if you
create a calculated field with a numeric argument such as
Expr1:Rnd(1)
Expr1:Rnd([Employee ID])
Expr1:Rnd(len([First Name]))
For more information about returning a random record please see the
following article in the Microsoft Knowledge Base:
Q108435 ACC: Sample Function to Return a Random Record
For more information about the TopValues property, search for "TopValues,"
and then "TopValues Property" using the Microsoft Access 97 Help Index.
Keywords : kbusage QryGnrl
Version : 2.0 7.0 97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 9, 1999