Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Select a record (Access 2000)

    Is there any way of selecting a record randomly in access??
    Please <img src=/S/help.gif border=0 alt=help width=23 height=15> moi!

    Kindest Request by
    Princess........

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Random Select a record (Access 2000)

    If you want to do this in a form, you can use the following code (to be used in the On_Click event of a command button, or something like that):

    Dim intRandom As Integer
    Dim CntRecord As Integer
    Dim rst As Object

    'Get table record count - replace tblImage by the record source of the form
    CntRecord = DCount("*", "tblImage")

    ' Set object variable
    Set rst = Me.RecordsetClone

    intRandom = Int(Rnd * CntRecord + 1)
    ' Move recordset to random record (offset from current one)
    rst.Move intRandom - Me.CurrentRecord
    ' Move form to same record
    Me.Bookmark = rst.Bookmark

  3. #3
    4 Star Lounger
    Join Date
    Aug 2001
    Location
    London, UK
    Posts
    516
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Random Select a record (Access 2000)

    Thank you soooooo much
    it works
    <img src=/S/bow.gif border=0 alt=bow width=15 height=15>

    Regards
    princess

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Random Select a record (Access 2000)

    What if the number of records exceeds 32,767, wont you need to define the integer variables as long integer?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Random Select a record (Access 2000)

    Pat,

    You're right. I copied this code from a recent thread started by Dave Willett in which he needed to select from only 4 or 5 records, so Integers were OK there.. I neglected to generalize it. Thanks for the heads-up.

Posting Permissions

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