|
-
Dec 2nd, 2002, 01:47 AM
#1
Thread Starter
Conquistador
Random row in Access
I was wondering if I could connect to an Access db, then pull a random row out of a table
"infos"
this is for a sort of "quote of the day" arrangement...
Could anyone help?
-
Dec 2nd, 2002, 04:01 AM
#2
Frenzied Member
Yes, I can think of two possible methods.
1. Number your rows (i.e. have a numeric, sequential primary key). Use VB's random functionality to get yourself a random number and do a SELECT...FROM...WHERE ID=MyRandomNumber
2. Pull the entire table into an ADODB recordset; use the same random functionality to get your random number, then use the Move method to move through your recordset to the random record.
-
Dec 2nd, 2002, 09:23 AM
#3
Thread Starter
Conquistador
yes,
i used this approach for any who may be interested
:
VB Code:
Randomize
randrow = CInt(Rnd * rs.RecordCount)
rs.Move randrow, 1
RandInfo = rs.Fields("infoText")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|