Find Random Record in Access 2010

I want to click a button on my vocabulary database, so that a random record is shown each time I click.

I could do it if there was an autonumberID, but in this case the unique field is the word itself (Required + Indexed + No Duplicates Allowed)
LVL 24
EirmanChief Operations ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
So why not add an autonumber?  It does not have to replace the unique field as a primary key.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EirmanChief Operations ManagerAuthor Commented:
So why not add an autonumber?
I will if I have to, but maybe someone will come up with a solution for this situation. It's a very basic database with no relationships.
0
mbizupCommented:
This solution uses a make table query to create a temp table, based on a select statement from your source table.

It then adds a field and updates it with random numbers, and finally orders the data by the random number so that you can use a Top N query to select however many random records you need:
http://fontstuff.com/vba/vbatut02.htm
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

EirmanChief Operations ManagerAuthor Commented:
Thanks mbizup (and well researched), I'm sure that will do the job, but I have decided not to use it, as the code is long and may need to be modified for access 2010.

While I was waiting for responses to roll in I took your advice and added an auto number field and filled it for every record (append query into a dataless table + the autonum field).

So I'm now going for a simpler solution. What do you think of this .....
http://www.cosnetics.co.uk/articles/select-random-records-from-access/

EDIT: I'm not sure where to use the code
SELECT TOP 5 * FROM [tableName] ORDER BY rnd(INT(NOW*id)-NOW*id)

EDIT2: got it
Me.RecordSource = "SELECT TOP 3 * FROM VOCAB ORDER BY rnd(INT(NOW*WORDid)-NOW*WORDid);"
0
EirmanChief Operations ManagerAuthor Commented:
My previous comment says it all.
Thanks mbizup.
0
mbizupCommented:
Glad you got it working.

I thought that the sheer volume of code in the fontstuff article, even though the method works,  actually in itself made a very good point of WHY you might want to simply go the autonumber route.    ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.