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?
Printable View
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?
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.
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")
;)