Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / July 2006

Tip: Looking for answers? Try searching our database.

select random record

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
darren - 31 Jul 2006 13:43 GMT
I am trying to randomly select a client on a form. The query behind the form
is as follows:

SELECT TOP 1 Rnd([ClientID]) AS Shuffle, tblClients.ClientID, tblClients.
Client
FROM tblClients
ORDER BY Rnd([ClientID]);

However, whenever the form is first opened it always diplays the same record,
when open a second time it always displays the same second record, etc. i.e.
it seems to always 'randomly' select  the same ones in the same order???

I have put a requery command in the OnOpen event of the form. What have I
missed?

Thanks in advance?

Signature

Darren

Allen Browne - 31 Jul 2006 14:46 GMT
Replace the Requery in Form_Open with:
   Randomize

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I am trying to randomly select a client on a form. The query behind the
>form
[quoted text clipped - 13 lines]
> I have put a requery command in the OnOpen event of the form. What have I
> missed?
darren - 31 Jul 2006 16:45 GMT
Thanks Allen.

It didn't solve it, but it did point me in the right direction.I took the Rnd
out of the query and into a function it seemed Randomize in the form did not
seem to reset the seed for the query.

Public Function fnRndNum(vIgnore As Variant) As Double

Randomize

fnRndNum = Rnd()

End Function

I then used this function in the same query and it worked.

Many Thanks

Signature

Darren

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.