Results 1 to 3 of 3

Thread: Using the "Random/Rnd" command....

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56

    Question

    Hi Everyone,

    Is it possible, using the random option that accompanies VB6 to "shuffle" the records in a table, in Access?

    If so, can you point me in the right direction?

    Thanks!

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56
    I need to pull the data out of a table, mix it up, and put it back into the same table.

    Any pointers, tips, suggestions?

    Thanks!

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Use an array

    I would not Post code without checking it, but can give you a general idea.

    Define a User Type consisting of an Integer and a Single. Then Dim an array of Types.
    Code:
    Public Type ShuffleType 'Could be Private, I think'
       RecordNumber As Integer
       RandomNumber As Single
     End Type 
    
    Dim ShuffleItem(1 to 500) as ShuffleType
    Use Dim & ReDim if Array cannot have constant for Upper Bound.

    Write a For-Loop which assigns integers 1 to Last to the integers, and which assigns a Random Number to the other variable.

    Sort the array by the random number. Use the sorted array to assign new positions to the records.

    I never used Access, but if it works like similar Products I have used, I suspect that you could get Access itself to do all the work. Put another field in each record to contain a Random Number. Assign Random Numbers to the new Field. Tell Access to sort by the field.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

Posting Permissions

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



Click Here to Expand Forum to Full Width