John Vinson posted most of this a while back. I've modified the function to
handle your specific case.
One problem is that this could generate duplicate numbers since it is
generating random numbers and does not check for the existence of a number
already in the set of records. Second problem is that the number generated
can be less then 8 digits since leading zeroes would get removed. You can
handle that by storing a string in a text field where you format the value
returned or you can change the code line assigning the value to read
something like the line below. That should take numbers smaller than the
required length and add zeroes to the end of the number. So if the number
generated was 1021 the function would return 10210000d (for eight digits)
RndInteger= CLng(LEFT(Int(Rnd() * 10 ^ vLength) &
String(vLength,"0"),vLength))
See
http://support.microsoft.com/default.aspx?id=208855
Copy and paste this little function into a module; save the module as
basRandom (anything except RndInteger, you can't use the same name twice);
Public Function RndInteger(vIgnore as Variant, vLength as Integer) As Long
'vIgnore is required to force a query to call the function for every row
'vLength is required to specify the size of the integer.
'vLength must be restricted to the range 1-15
Static bRnd As Boolean
If Not bRnd Then
Randomize
bRnd = False
End If
RndInteger= Int(Rnd() * 10 ^ vLength)
End Function
Then include a calculated field in the Query by typing:
Shuffle: RndInteger([somefield],8)
Where "somefield" is any numeric field in your table - this just forces
Access to give you a new random number for every row. If you don't have a
numeric field available then you can use RndNum(Len([SomeField])) to force a
number to be generated.