Click to See Complete Forum and Search --> : Random Searches


KMason55
July 23rd, 1999, 10:40 AM
This actually deals with Visual Basic and Access. Here's the scenario: I have an Access Database that I want to do a query/report on. I have a selection criteria screen which can return the results of my query into the report. My results always comes up in the order that the data is stored in the database. I want my data to be returned in a random order.
I thought about adding a numeric field to the Table and leaving it blank. Is it possible to generate a random number using Visual Basic and assign that number to that numeric field, then sort on that field so that everytime I run the query, it will be in a different order? Or does anyone know of a way of returning a search in random order. I eventually want to move this to a website, so do you think that Visual InterDev could return a search in random order?

Lothar Haensler
July 23rd, 1999, 10:54 AM
that's a funny requirement, that I've never heard before.
I'd read all rows from your query using the GetRows method of the recordset object.
Then, all your rows are in memory.
You can then use VB's Randomize statement and Rnd function to display your records in a random fashion.

if you query returned e.g. 6 records you could use this code to get a random number.
MyValue = Int((6 * Rnd) + 1) ' Generate random value between 1 and 6. (stolen from the vb docs).

Just store you numbers in an array so as to avoid displaying the same record multiple times.