473,618 Members | 3,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6261
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.co m> wrote in message news:<e2******* ***********@new sread1.news.pas .earthlink.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(KeyFieldNam e) 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 QryExcelExportB ase.*
FROM QryExcelExportB ase
ORDER BY Rnd(QryExcelExp ortBase.CSGTran sID);
Nov 12 '05 #3

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

Similar topics

3
1690
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. I want one that if the number picked is 0 through 99 it is generated as 000 through 099. Can anyone help me with this? Cause I'm stumpt.
2
1304
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 number between 1 and <recordcount> and then move to this record in the recordset. There is a easier way, isn't it?
7
6932
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
1561
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 way but it has me foxed! Hoping someone can help
2
1452
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 specify that it only happens once a day. This is the select statement I'm using to generate a random record. Dim queryString As String = "SELECT Top 1 . FROM ORDER BY NEWID()"
19
2136
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 or post), I send the id to my script and delete the record (DELETE FROM table WHERE id=some_validated_input). The problem is if I'm a nasty guy I just write my own form and delete any
26
3136
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 need to open the DB and randomly select a record (and then display the name, which i dont have a problem with) how can i randomly select a record? im guessing id have to open a recordset
48
4232
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) * -1 Set oConn=Server.CreateObject("ADODB.Connection") Set oRS=Server.CreateObject("ADODB.recordset") oConn.Provider="Microsoft.Jet.OLEDB.4.0" oConn.Open Server.MapPath("temp.mdb")
2
1941
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 record? Any pointers would be great. Thanks Richard <% ' ADO Constant. Dont change this ' Connection string and SQL statement
0
8212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8595
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8304
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7126
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6101
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2587
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.