Solved

rand() in access 2000 ?

Posted on 2003-11-03
2
1,192 Views
Last Modified: 2006-11-17
hi!

i have written a program using mysql.
in a query i´m using order by rand().

now i have to switch to access. but it seems that
there is no rand() function.

how can i handle this?
0
Comment
Question by:StoreMaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
heer2351 earned 50 total points
ID: 9669772
The msaccess equivalent for rand is rnd
0
 
LVL 77

Expert Comment

by:peter57r
ID: 9669830
There is a rnd() function in Access; but you can't use it in the way you are trying to.

To generate a random field in a query you need to force Access to think that the random number is dependent on a field in the record or else the rnd() value is just calculated once at the start of the query and that value used on all records.

So you can include rnd([anyfield]) and this produces a different result for each record.

You can sort on this value in a query.  Unfortunately, by the time the data is displayed, the random function has triggered again and the numbers have changed so that they appear not to be in order.   If you want to retain the random number sequence you must first write the value to a new field in an update or make-table query and then use another query to present the sorted data.

Pete


0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question