Random Numbers

  • Thread starter Thread starter Paul S
  • Start date Start date
P

Paul S

Let me rephrase that... I want to generate a list of numbers in "random"
order between 1 and 50...
 
Let me rephrase that... I want to generate a list of numbers in "random"
order between 1 and 50...

You can use the Top Values property of a query, with help
from a little VBA. Create a table of sequential numbers. Put this little
function into a Module:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

Then add a calculated field to your Query by typing

Shuffle: RndNum([fieldname])

in a vacant Field cell, where [fieldname] is any field in
your table - this forces Access to give a different random
number for each record.

Sort the query by Shuffle, and set its Top Values property
to the number of records you want to see.
 
Thanks John, that did it!

John W. Vinson said:
Let me rephrase that... I want to generate a list of numbers in "random"
order between 1 and 50...

You can use the Top Values property of a query, with help
from a little VBA. Create a table of sequential numbers. Put this little
function into a Module:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

Then add a calculated field to your Query by typing

Shuffle: RndNum([fieldname])

in a vacant Field cell, where [fieldname] is any field in
your table - this forces Access to give a different random
number for each record.

Sort the query by Shuffle, and set its Top Values property
to the number of records you want to see.
 
Back
Top