random sort

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok i just type this and didnt come thru so if you see this twice im sorry

I need help with the rnd function. I cant get it to work. I have search
thru the forums and was unable to get it to work.

So i have a table that has 8 fields, question #, question answer a, b, c,
d, etc

I want to sort by randomly by question #. So each time i sort i dont get
the same test. I have figured out how to use the top 100 function in the
quesries. Just figure out how to randomly sort these.

Please be detailed in your response. Thanks in advance
 
Ok i just type this and didnt come thru so if you see this twice im sorry

I need help with the rnd function. I cant get it to work. I have search
thru the forums and was unable to get it to work.

So i have a table that has 8 fields, question #, question answer a, b, c,
d, etc

I want to sort by randomly by question #. So each time i sort i dont get
the same test. I have figured out how to use the top 100 function in the
quesries. Just figure out how to randomly sort these.

Please be detailed in your response. Thanks in advance


You can use the Top Values property of a query, with help
from a little VBA. Put this little function into a Module (save the
module with a unique name, NOT RndNum - I'd suggest basRndNum).

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.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top