Sample Population

  • Thread starter Thread starter Lecreia
  • Start date Start date
L

Lecreia

Does anyone know if Access allows you to sample a table
or query in Access? If so, please let me know
 
By "sample", I assume you mean choose a random selection of a specified
size.

Assuming the table has a primary key named "ID", here are the steps:
1. Create a query into the table.

2. In query design view, type this into a fresh column, the Field row:
Rnd([ID])
In the Sorting row under this field, choose Ascending.

3. In the Properties box (View menu), enter the number of records you want
as your sample beside the Top Values property.

4. Open the Immediate window (Ctrl+G), and type in:
Randomize
and press Enter.

5. Run the query.

Explanation:
The query generates a random number on every row, sorts by that (i.e.
randomly sorted) and select the TOP xx records. The Rnd() function does not
actually do anything with the autonumber, but if you don't pass in something
that changes on every row, the query engine doesn't bother calling the
function again each time. The Randomize statement must be issued once per
session to get a random selection.
 
Back
Top