Random Record From Database

Results 1 to 2 of 2

Thread: Random Record From Database

  1. #1
    Join Date
    Dec 1969

    Default Random Record From Database

    Can anyone help me streamline this please ?<BR><BR>I would like to display a randomly selected record from my database.<BR><BR>I use RecordCount to determine the number of records in a recordset (the current example has 13)<BR><BR>(not sure of the correct code for this bit) - I select a number between 1 and 13 (the number of records counted) - For this example 7. and then go thru the recordset till i get to the 7th record and display the contents.<BR><BR>Can anyone help me with the random select bit? I know I would need to use Randomize but am not sure how to do so.<BR><BR>Thanks!!!<BR>Renee<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default ASPFAQs, topic: Databases, Queries

    Shows how to get multiple random records, but the principle is the same.<BR><BR>But if you can get the RS.RecordCount, you can simplify it all a bit if you only want one random record:<BR><BR>&#060;%<BR>...<BR>RS.Open ....<BR>which = Int( Rnd * RS.RecordCount )<BR>If which &#060;&#062; 0 Then RS.Move which<BR>...<BR>%&#062;<BR><BR>That should be all you need. You might not even need the IF WHICH test, but I&#039m being paranoid.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts