Results 1 to 3 of 3

Thread: Random row in Access

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    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?

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    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.

  3. #3

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yes,

    i used this approach for any who may be interested
    :

    VB Code:
    1. Randomize
    2. randrow = CInt(Rnd * rs.RecordCount)
    3. rs.Move randrow, 1
    4. 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
  •  



Click Here to Expand Forum to Full Width