Results 1 to 5 of 5
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Setting Random Order

    I want a query to pull some records in random order. I would like it to be a different order each time. This is to mix up questions on a test each time it is given. I've tried using the rnd() function, but it gives the same value for each record. So far I haven't found a good way to do this. Any suggestions?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think that has been asked in forum, but finding it again would be a challenge.

    Bing: query random records

    http://access.mvps.org/access/queries/qry0011.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Put this code in a standard module (for example, mdlRandomizer).
    Code:
    Option Compare Database
    Option Explicit
    ' Function NewRandom
    '
    ' The input parameter can be any text or number field
    ' available to the query.
    ' The value of the parm itself is totally ignored, but it is there
    ' so that, in a query, the function will be called once for each 
    ' record and therefore each record will be assigned
    ' a different random number between 0.0000 and 1.0000
    '
    '
    Public Function NewRandom(ThisParmWillBeIgnored As Variant) As Single
       Static AlreadyRandomized As Boolean
       
       ' The first call (only) will randomize the seed using
       ' the system time
       If Not AlreadyRandomized Then
          Randomize
          AlreadyRandomized = True
       End If
       
       NewRandom = Rnd()
       
    End Function

  4. #4
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Dal,

    It worked fine.

    Thank you for a solution that was easy to implement.

  5. #5
    Paul H's Avatar
    Paul H is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    June,

    Your code was almost identical.

    Thank you too.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Allow more than order in an ORDER form.
    By kiko in forum Access
    Replies: 37
    Last Post: 04-19-2013, 05:30 AM
  2. How to order columns in ascending order?
    By darkingthereturn in forum Access
    Replies: 5
    Last Post: 06-18-2012, 05:24 AM
  3. Random 0 now
    By Mounds in forum Access
    Replies: 4
    Last Post: 04-29-2011, 10:04 AM
  4. order by setting itself
    By byterbit in forum Reports
    Replies: 1
    Last Post: 02-02-2011, 08:59 AM
  5. Setting a field in order for Report
    By cotri in forum Reports
    Replies: 2
    Last Post: 01-28-2010, 02:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums