Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random records from Access

Status
Not open for further replies.

DreadPirate

Technical User
Sep 3, 2001
8
US
Howdy folks,

There was a previous question for this a while back ago but it was never really answered clearly. I'm trying to call a random record from an Access 97 table and display one of the fields in a text box. I think I can handle the displaying part =), but I'm real fuzzy on the whol erandom call thing. I understand I need to use the RecordCount property and probably a random function somewhere along the way, but, being fairly new to VB, I'm just not sure how to do it. Someone said something about rs.move, also, but not only do I not understand what that is, frankly, it scares me ;).

Any help in this matter would be eternally appreciated (or at least until my next problem).

Thanks much.

{R}
 
First get your recordset, then generate a random number between 1 and the size of your record set, for example :

MyValue = Int((RS.RecordCount * Rnd) + 1)

RS.Move MyValue,1 '1 means the start of the recordset

You will now be pointing at a random record in your set, so display as normal.

Hope this helps,

Dan.
 
Oh yeah, you will need to put the command RANDOMIZE in first, so ...

RANDOMIZE

MyValue = Int((RS.RecordCount * Rnd) + 1)

RS.Move MyValue,1 '1 means the start of the recordset


Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top