How do I automatically select a database record randomly?

I

Italian1

Hello,
I have an Access Database of students who have taken an examination. I would
like to automatically and randomly select one of those students who passed
the examination with a score of 85% or higher.

Note: I also have the same database in Excell. I am willing to use Excell
and/or Access if someone can show me how.

Thanks for the assistance.
 
J

John Spencer

See http://support.microsoft.com/default.aspx?id=208855

Copy and paste this little function into a module; save the module as
basRandom (anything except RndNum, you can't use the same name twice);


Public Function RndNum(vIgnore as Variant) As Double
'Source J. Vinson
Static bRnd As Boolean
If Not bRnd Then
Randomize
bRnd = True
End If
RndNum = Rnd()
End Function

Now use that in the Order by clause of your query along with TOP 1 to
limit to one record being returned

SELECT Top 1 StudentID
FROM SomeTable
WHERE Score >.85
ORDER BY RndNum(StudentID)

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

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

Top