Results 1 to 4 of 4
  1. #1
    shredsec is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    3

    Display random record with button


    My button runs a query that finds a random record from my table (the code is below). But when I press the button to run it, the query opens and doesn't display my data in the form.

    SELECT TOP 1 [>75 employees].*
    FROM [>75 employees]
    ORDER BY Rnd([id]);

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    That is all of the code for the button??

  3. #3
    shredsec is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    3
    Quote Originally Posted by ssanfu View Post
    That is all of the code for the button??
    The code runs the query and I've added a button that runs the code. It's obviously missing something because the result of pressing the button on the form is that a datasheet view of the random record is displayed.

  4. #4
    shredsec is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    3
    I found the answer elsewhere on the web...add this code into the button's click event and it displays a randomised record:

    DoCmd.GoToRecord , , acGoTo, Int(Rnd() * Me.RecordsetClone.RecordCount) + 1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Bind item() to button text at random
    By timosilver in forum Access
    Replies: 0
    Last Post: 02-26-2012, 12:08 PM
  2. Replies: 5
    Last Post: 12-24-2011, 06:04 PM
  3. Replies: 1
    Last Post: 12-05-2011, 03:26 PM
  4. Random Record pull
    By Madmax in forum Access
    Replies: 2
    Last Post: 06-28-2011, 08:26 PM
  5. random record
    By wasim_sono in forum Programming
    Replies: 1
    Last Post: 02-06-2008, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums