Random Query in Access

Results 1 to 3 of 3

Thread: Random Query in Access

  1. #1
    JBlain Guest

    Default Random Query in Access

    I am trying to build an Access database that will randomly sort names that I enter into groups of four.

  2. #2
    <eop> Guest

    Default Cool! Let us know how it turns out!


  3. #3
    Join Date
    Dec 1969

    Default Rephrase question?

    Do you want the table (I presume a table, not every table in the database) to be *presorted* into groups of 4? Such as assigning a "GroupID" to 4 users randomly, then the next group id to another 4 users, etc. And leaving this in place in the DB?<BR>[This is tough...slow, too. Probably easiest to read all the data into an array and then create a *new* recordset that has the grouping done. What do you do if there are 11 people? Only 3 for the last group. Oops? Probably best done with a second table that simply relates group numbers to user id numbers?]<BR><BR>Or do you want to do a query that gets you groups of 4? This is really the same solution: Get all the data into an array and then process the array. But you just don&#039;t write the groups back into the table(s).<BR><BR>As to how to get the groups of 4 from the array:<BR><BR>See the ASPFAQs, category MATH. Look for the FAQ on "shuffling a deck".<BR><BR>Basically, you can use that code. You get the array (via RecordSet.GetRows, presumably). And then you ask to Shuffle the "deck" but get only 4 "cards" back. You get back an array of 4 people. And you repeat the operation until the "deck" has fewer than 4 cards left.<BR><BR>You&#039;ll have to adapt the code there quite a bit: You&#039;ll be using a two-dimensional array instead of the singly-dimensioned I show. And you&#039;ll want to start with element zero of the array (the code there starts with element one). But the concepts are all the same.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts