Solved

random databases.

Posted on 2000-02-17
8
211 Views
Last Modified: 2010-05-02
I've got a relatively small database sorted by number.

How can I sort this to display these entries in a random order, each time I run the program, and not repeat entries?
0
Comment
Question by:SRP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 2532715
You could add an extra field to the recordset, then fill this with a random number and order it on this.

rstRandom.Open "SELECT Number,Field1,Field2...Field3,Random = 0.0 FROM TableName",cnnDatabase,adOpenStatic,adLockOptimistic
With rstRandom
  .MoveFirst
  Do
    !Random = Rnd() * 100
    .MoveNext
  Loop Until .Eof
End With
rstRandom.Sort = "Random"

Or something like that anyway.
0
 
LVL 1

Accepted Solution

by:
georgeman earned 50 total points
ID: 2532754
Try this algorythm:

- load all db records in rs recordset

- get number records in recordset
  rs.MoveLast
  NumberRecords = rs.RecordCount

- create new empty recordset newrs

- create array(NumberRecords) as integer (or long if you have big database)

- for i=1 to NumberRecords
     'get random number
 repeat1:
     RandomNumber = Rnd()
    'if RandomNumber doesn't exist in array - add it to array
    'else goto Repeat1

     'get record number=RandomNumber from rs recordset
     rs.findfirst "number = " & RandomNumber
    'upload record from rs to newrs
  next i

- newrs is now copy of rs but organised in random order.

Regards
George
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2532767
That would work as well.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Expert Comment

by:georgeman
ID: 2532777
Sorry TimCottee
I did not see your comment when I created my own.
George
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2532787
That is OK, you used a different method though the thought process is obviously similar.
0
 

Author Comment

by:SRP
ID: 2537985
This is a v. good answer, and a very simple. But one brief question, will it produce a different random order each time the program runs?

OK cheers.
SAM
0
 
LVL 1

Expert Comment

by:georgeman
ID: 2540481
It depands how you will organise the process of creating of random numbers. One tip: you can use for that current date/time info so random numbers will be really random because these values are unique for every time when you start your program (or when you start this process inside program).
George
0
 

Author Comment

by:SRP
ID: 2543663
Cheers, I thought I had already accepted the answer. Obviously not!

Here are the points.

Thanks
SAM
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 137
VBA: Select SQL query based on a config Sheet v2 11 52
MsgBox 4 71
Export PDF Form fields to Access  or Excel  in Tab order 16 113
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question