Home  |  About  |   Search   

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

RunCommand Constants

Terms of Use


 

Queries: Create a query that returns Random records

Author(s)
Joe Foster

(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)


1998-2009, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer