473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Random Record Selection from Access 2000

Hi Guys, i have an access database with 5 records in and i need to show them
in a random order every time the page is refreshed or reloaded.

i've searched round and tryed no end of code but nothing seems to work.

i just need something really simple that selects a random feild from my DB.

Sql = "SELECT * FROM tblmain ORDER BY RND()" - ive tryed this and it just
shows the results in teh same order.

this is desperate help is need and will be gratefully recieved.

thanks

Jamie
Jul 19 '05 #1
2 7757
Hi,

You could do one thing. Get all the ids of the columns into an ASP array, and using the Randomize and RND() function, pick up any one of the array element and then select the database using that id. Like....

<%
'Randomizing the Id of the Term column
'--------------------------------------------------------
Function RandomNumber(intHighestNumber)
Randomize
lowerbound = 0
upperbound = intHighestNumber
randomIndex = Int( ( upperbound - lowerbound + 1 ) * Rnd + lowerbound )
RandomNumber = randomIndex
End Function

Set oRs = Server.CreateObject("ADODB.Recordset")
oRs.Open "select iTermId from Term_MST", objConn
If not oRs.EOF Then
myArr = oRs.GetRows()
s = uBound(myArr,2)
rndId = myArr(0,RandomNumber(s))
Else
rndId = 0
End If
oRs.Close
Set oRs = Nothing
'-----------------------------------------------------------------

Set objRs = Server.CreateObject("ADODB.Recordset")
objrs.Open "select vTermName, vImageURL from Term_MST where iTermId= "&rndId&"", objConn
If not objrs.EOF Then
term = objRs("vTermName")
url = objRs("vImageURL")
End If
objRs.Close
Set objRs = Nothing
%>

REgards,
Bhaskardeep Khaund
Jul 19 '05 #2
http://www.aspfaq.com/2132

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Jamie Fryatt" <ja**********@btconnect.com> wrote in message
news:bq**********@titan.btinternet.com...
Hi Guys, i have an access database with 5 records in and i need to show them in a random order every time the page is refreshed or reloaded.

i've searched round and tryed no end of code but nothing seems to work.

i just need something really simple that selects a random feild from my DB.
Sql = "SELECT * FROM tblmain ORDER BY RND()" - ive tryed this and it just
shows the results in teh same order.

this is desperate help is need and will be gratefully recieved.

thanks

Jamie

Jul 19 '05 #3

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

Similar topics

4
by: Keith Griffiths | last post by:
I'm trying to do a search under a set criteria followed by a selection of random entries meeting this criteria. But I don't seem to be able to achieve this. The idea being to search on say...
5
by: Jamie Fryatt | last post by:
Hi all, im a little bit new to all this so i you could help me a little i would be greatful. How do i select a completly random record from a database? sql = select (random) from tbl, sort of...
3
by: jaYPee | last post by:
anyone know how can i get a 10% random records out of 2000 records? 2000 is only an example and it will vary anytime. i want to create a report out of this 10% thanks in advance
1
by: Micak | last post by:
I'm using radnom selection in ms access to select certain number of questions for the exam. i have two versions of the report: - one without marked answers - one with marked answers the problem...
7
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;
2
by: Lyn | last post by:
If I have a form where the RecordSource property is set to the name of a table, then on opening the SingleForm form I can cycle through all the records in the table one at a time via Next and...
1
by: moelleni | last post by:
Hi, I made an Access 2002 Database and wanted to automate it to sent the current record to Word 2002. So readed the article "How to send the current record to Word 2000 with automation" I tried...
2
by: IceCube | last post by:
Hello, I would like to select/filter at random 30 records out of an Access-table of 1500 records. I know the option "Top" which gives me the possibility to see the 30 first records of the table...
48
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) *...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.