Hi Rod,
In addition to the sage responses...
If I had a table and I wanted to add
a field that had random numbers >0
and <21, I would add following function
to a code module (say "modRandom")
'************ Code Begin ***********
'Code courtesy of
'Joe Foster
'
http://www.mvps.org/access/queries/qry0011.htm
Function Randomizer () As Integer
Static AlreadyDone As Integer
If AlreadyDone = False Then Randomize : AlreadyDone = True
Randomizer = 0
End Function
'************ Code End *************
Then I would add a field (say "fRnd") of type Long
to my table (say "yurtable") which also has some other
field (say "somefield"),
then run following update query
UPDATE yurtable
SET [fRnd] = Int(20 * Rnd(1 + Len([somefield] & "")) + 1)
WHERE randomizer()=0;
from Access Help:
*** quote ***
Rnd() returns a random number of type SINGLE.
You could use an upperbound and lowerbound to get random integers in a
given range.
RandNum = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
*** unquote ***
so...
substituting upperbound=20 and lowerbound=1,
[fRnd]=Int((20 -1 + 1) * Rnd() + 1)
Rnd() needs a non-negative, non-zero, non-null argument
or else all our results would be the same.
So we feed it the length of some field (plus make sure it is
non-negative, non-zero, non-null) from the same record we
are computing our random number:
[fRnd]=Int((20 -1 + 1) * Rnd(1 + Len([somefield] & "")) + 1)
all that's left is to reduce the math...
good luck (maybe w/your homework?),
gary
Rod said:
When set to autonumber random it placed incremental numbers in the field
for
each record. Would I have to delete and re-import the data for this to
work
correctly? How would I make sure the random numbers are >0 and <21?
Thanks