How to populate a field with a four digit random number?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How to populate a field with a four digit random number when new record is
added (similar to RANDBETWEEN function in Excel)?
 
I don't think there's a built in function for it in Access, but you can
always create a function in VB and use it wherever you wanted.

Function fRandom(LowNumber As Double, HiNumber As Double) As Integer
fRandom = Int((HiNumber - LowNumber) * Rnd + LowNumber + 1)
End Function

Then use
=fRandom(1000,9999)
as your default value.


It's much easier to just use the random AutoNumber type for the field, but
it won't limit it to a 4 digit number.
 
Back
Top