Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - random selection of records in a table
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

random selection of records in a table

 Post Reply Post Reply
Author
moti View Drop Down
Groupie
Groupie


Joined: 07 September 2004
Status: Offline
Points: 73
Post Options Post Options   Thanks (0) Thanks(0)   Quote moti Quote  Post ReplyReply Direct Link To This Post Topic: random selection of records in a table
    Posted: 06 March 2005 at 2:42am
how could I make a code to on each page refresh select a record from a table in random

for example in first refresh it will select record with ID 5  and in second refresh it will select Record with ID 45  and ...
 
 
 
Back to Top
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Post Options Post Options   Thanks (0) Thanks(0)   Quote bootcom Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2005 at 2:53am
Here's a quick snippet of code I use, that basically pulls a random record from the database so you get a different record every refresh
 

' ADO Constant. Dont change this
Const adCmdText = &H0001
 
rs.open strSQL, adocon, 3, , adCmdText

' Generating random number from total number of records
Dim intRnd
Randomize Timer
intRnd = (Int(RND * rs.RecordCount))
' Now moving the cursor to random record number
rs.Move intRnd

 ' Closing the database
rs.Close
Set rs = Nothing
Back to Top
moti View Drop Down
Groupie
Groupie


Joined: 07 September 2004
Status: Offline
Points: 73
Post Options Post Options   Thanks (0) Thanks(0)   Quote moti Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2005 at 2:58am
thanks but I can't understand above code could you send it
again with a little description
Big smile
Thanks
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2005 at 3:41am
Not sure about in access but in SQL Server  you can use
 

SELECT * FROM YourTable ORDER BY NEWID()
 
as your SQL Query
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.