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);