I need to pull random records (non-inclusive membership numbers) from a query.
What criteria do I need in the query so that I can run the query from a form
that allows me to get records for example: memnumbers 1121,1243,1344,2172
etc?
As opposed to all records between 1121 and 2172...
Thanks
One way is to shuffle the records in random order, and return the top
ten records (if you want to see ten randomly selected ones).
It helps to have a small VBA function to do this. Open a new Module,
and copy and paste this into it:
Public Function RandNum(vIgnore As Variant) As Double
Static IsRandomized As Boolean
If Not IsRandomized Then
Randomize ' Initialize the random number generator
IsRandomized = True ' but only the first time it's called
End If
RandNum = Rnd()
End Function
Then in your Query, include a calculated field:
Shuffle: RandNum([memnumber])
Sort by this field, and you'll present the members in scrambled order.
You need to pass a value to the RandNum function to force Access to
call it on every row. If you just try to sort by Rnd() it won't work,
since it will call Rnd() only once and repeat the value.
John W. Vinson[MVP]