How to get a random recordset from a query

ChipperT

Banned in 13 Countries
Local time
Today, 15:12
Joined
Jun 1, 2010
Messages
347
I have a simple table:

ID (autonumber - PK)
Description (text)
Status (integer - FK)
StatusDate (datetime)

I would like to create a query that will return a random set of N records where N is an integer less than the total number of records in the table.

For example, if I have a table of 35 records and the user specifies that they want 12 records in the recordset, teh query should return 12 random, unique records in the result. Any help would be appreciated.
 
Something similar has been covered a few times on here.

What you need is the Rnd() function which you would use in the WHERE part of the query.

To get the number of records you need TOP.

The query would need to be built using vba.
 

Users who are viewing this thread

Back
Top Bottom