By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,505 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,505 IT Pros & Developers. It's quick & easy.

Pick a record at random

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.