473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Pick a record at random

Ini
Hi,

Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?

I was thinking about doing a recordcount of the recordset, then find at
random the number between 1 and <recordcount> and then move to this record
in the recordset.

There is a easier way, isn't it?

Thanks

Ini.
Nov 12 '05 #1
2 1292
Ini wrote:
Hi,

Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?

I was thinking about doing a recordcount of the recordset, then find at
random the number between 1 and <recordcount> and then move to this record
in the recordset.

There is a easier way, isn't it?

Thanks

Ini.


How else would you be able to do it? I haven't seen a command to
findfirst a random record or open a table in random order? There is a
command to find a random value in a field...see Dfirst()/DLast() but you
want a record, not value. Your best option is to check out Randomize
and Rnd() in help. Once you have the random number you should move to
the first record and move the number of records minus 1.

Nov 12 '05 #2
Salad <oi*@vinegar.com> wrote in message news:<e2******************@newsread1.news.pas.eart hlink.net>...
Ini wrote:
Hi,

Is there an easy way to pick at random one record out of a recordset and
then leave this recordset?

I was thinking about doing a recordcount of the recordset, then find at
random the number between 1 and <recordcount> and then move to this record
in the recordset.

There is a easier way, isn't it?

Thanks

Ini.


How else would you be able to do it? I haven't seen a command to
findfirst a random record or open a table in random order? There is a
command to find a random value in a field...see Dfirst()/DLast() but you
want a record, not value. Your best option is to check out Randomize
and Rnd() in help. Once you have the random number you should move to
the first record and move the number of records minus 1.


Yes you can select a random record if your recordset has a unique
number associated with each record. If you Select Top 1 then put an
Order by RND(KeyFieldName) you will get a random record return.
Run Randomize then setup your query.

Here is an example of a query that will return 1 random record. In
this case CSGTransID is an AutoNumber. Look at Randomize and Rnd help
within access if you need further explanation.

SELECT TOP 1 QryExcelExportBase.*
FROM QryExcelExportBase
ORDER BY Rnd(QryExcelExportBase.CSGTransID);
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Diodak | last post by:
**************************************** How can get RANDOM record from XML file? **************************************** for e.g. in xml files i have aprox.200 records. how get random position...
3
by: Jules | last post by:
I've searched high and low for a 3 digit number generator that will pick at random a number between 000 and 999. The only things I have found were generators that pick numbers from 0 to 999. ...
2
by: Ini | last post by:
Hi, Is there an easy way to pick at random one record out of a recordset and then leave this recordset? I was thinking about doing a recordcount of the recordset, then find at random the...
7
by: Bill | last post by:
Hello, I am trying to use a SQL Query to return a random record from an Access 2000 Database. I am using: SELECT TOP 1 Example FROM TABLE ORDER BY Rnd;
1
by: Ken Gray | last post by:
Hi all Anyone help me find a way of randomly selecting a record from a table for display on a form. Do I need to somehow re-seed the random generator? I am sure there must be an easy, simple ...
2
by: Pete via DotNetMonster.com | last post by:
Hi, I need to display a different random record or link each day. I have the random part working so that if the browser is refreshed a new record will display. I'm not sure however how to...
19
by: MaXX | last post by:
Hi, I hope I'm not OT. I have the following issue: I want to delete a record from my db with a php script. Let's say I'm auth'd and I want to delete the record id 440. With a simple form (get...
26
by: Jimmy | last post by:
ill have a database with 1 table and 3 fields: ID FIRSTNAME LASTNAME (the ID field will be the auto incrementing index) there might be 10 records in the DB, there might be 10,000. i...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
2
by: fran7 | last post by:
Hi, I wonder if anyone could point me in the right direction. I have this script that gets a random record from my database. All records have an id, how do I instead of random just go to the next...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.