S
Stephen Simons
Thanks to John Vinson I have got the following module doing exactly what I want. Many thansk, John!
Would it be possible to refine it by having the query ask, via a dialog box, the number of records I want to randomly
select?
I've had a look at some of the samples, but cannot quite get there. A pointer in the right direction would be
appreciated.
TIA
Steve
You can use the Top Values property of a query, with help
from a little VBA. 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.
remove "_ILY_" to email me
email to (e-mail address removed)
Would it be possible to refine it by having the query ask, via a dialog box, the number of records I want to randomly
select?
I've had a look at some of the samples, but cannot quite get there. A pointer in the right direction would be
appreciated.
TIA
Steve
From a dbs containing several thousand records, I would like to be able to choose all that meet a certain criteria (say
one field is equal to, or greater than, zero); and then from the records that meet that criteria, randomly select a
sample of say 20.
I can achieve this relatively easily in XL, using formulae and some VBA code.
Can anyone point me towards the right approach for Access?
You can use the Top Values property of a query, with help
from a little VBA. 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.
remove "_ILY_" to email me
email to (e-mail address removed)