Using Rnd() in an Append query

D

Dennis Snelgrove

I'm trying to populate an Intersection table with several thousand random
records in order to give myself some data to work with during the
construction of the DB. I'm trying to use "int(Rnd(1)*50)+1" as the formula
to fill in a Score field, but it only calculates this once, then applies
that value to every record in the table. How do I get it to calculate a new
random value for every record?

Thanks...
 
K

Ken Snell [MVP]

The trick is to force the query to call Rnd() every record. One way to do
this is to replace Rnd(1) in your current expression by Rnd([field]), where
[field] is any non-negative number field in the table. This method uses two
facts:
-- the fact that passing Rnd() a positive number has the same effect as
passing no argument (a negative argument sets the seed
value for the random number algorithm);
-- the fact that ACCESS will call the function for each record because
you use a Field instead of a constant in the expression.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top