Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    I would not use the RND function alone. Basically the seed value of the random function does not change, so if you open your database, select your 'random' items. Then close the database, select the 'random' items again you will get the exact same set of records. That is the whole point of using a VBA module and using the RANDOMIZE function, because it reseeds your database. Do not use RND by itself if you value a truly random sample.

    To itsme.. I adapted some code I found elsewhere and didn't spend a whole lot of time examining it, I got a sample working and that was all I was interested in

  2. #17
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by rpeare View Post
    To itsme.. I adapted some code I found elsewhere and didn't spend a whole lot of time examining it, I got a sample working and that was all I was interested in
    Oh, I thought you mentioned that the table was not populating with an actual random number. Just for the fun of it, I created a little snippit for a random function.

    Code:
    Dim iRecNum As Integer
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("Table1", dbOpenDynaset)
    Dim max As Long
    max = 40
    Dim i As Integer
    Dim intCount As Integer
    intCount = 50
        For i = 0 To intCount - 1
            Randomize
            iRecNum = (max * Rnd) + 1
            
                rs.AddNew
                    rs![RandomNum] = iRecNum
                rs.Update
        
        Next i
    rs.Close
    Set rs = Nothing

  3. #18
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Yeah the problem I ran into was that if I used RANDOMIZE in a module I could not get it to carry through to a generated SQL statement so I had to create a dataset, then generate a random number between 1 and the maximum number of records then cycle through the recordset to pull the random record. It's not pretty but I tested it several times and got, what I thought, was a truly random selection every time.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. GROUP by yet SELECT fields not within GROUP BY
    By johnseito in forum Access
    Replies: 25
    Last Post: 11-03-2013, 10:20 PM
  2. Replies: 11
    Last Post: 01-25-2012, 09:46 AM
  3. Replies: 5
    Last Post: 07-29-2011, 11:54 AM
  4. Limit number of records in report by group
    By Dr Ennui in forum Reports
    Replies: 0
    Last Post: 06-22-2010, 12:36 AM
  5. Replies: 1
    Last Post: 03-12-2009, 09:55 AM

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