Rnd function

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Rnd function

Post by matthewR »

How would you use the Rnd function in a query. Is the function called rnd or Rand?

User avatar
HansV
Administrator
Posts: 78492
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Rnd function

Post by HansV »

The function is called Rnd. If you use Rnd() in a query, you'll get the same random value in each record. If you want a different value in each record, you must use Rnd([FieldName]) where FieldName is the name of any numeric field in the table(s) that the query is based on.
Rnd.png
The values will change each time the query is run or refreshed.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Rnd function

Post by matthewR »

How do you get 1500 records say?

User avatar
HansV
Administrator
Posts: 78492
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Rnd function

Post by HansV »

I'm sorry, what do you mean? Do you want to draw a random sample from a table with many records?
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Rnd function

Post by matthewR »

Yes

User avatar
HansV
Administrator
Posts: 78492
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Rnd function

Post by HansV »

The idea is as follows:
- Add a column to the query using Rnd([FieldName]) where FieldName is any number field.
- Sort on this field (ascending or descending, it doesn't matter).
- Click in an empty part of the upper half of the query design window.
- Set the Top Values property of the query to 1500 (you can't select this value from the dropdown list but you can type it in yourself).
x339.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Rnd function

Post by matthewR »

Thanks. That is what I need...