Randomize records

  • Thread starter Thread starter RRKEM
  • Start date Start date
R

RRKEM

I have a form with a subform. The form relates to "Patient's details" and the
subform has a number of radiologic images related to the patient (one to many)
. Because of the images, I need to see the database in the form you. I use
this to teach and see as "unknowns". Hence, I would like the order of
patients to change each time I open the application. Is there any way to do
this in the form view. I have an autonumber field for the form.
 
http://www.mvps.org/access/queries/qry0011.htm

(Q) How can I return Random records from a table?

(A) Paste the following function in a new module.

'************ Code Begin ***********
'Code courtesy of
'Joe Foster
Function Randomizer () As Integer
Static AlreadyDone As Integer
If AlreadyDone = False Then Randomize : AlreadyDone = True
Randomizer = 0
End Function
'************ Code End *************

Now to get 100 questions picked at random:

select top 100 mytable.*from mytable
where randomizer() = 0
order by rnd(isnull(mytable.question) * 0 + 1)
 
Back
Top