generate a random 6 digit number

S

summernight

how do i change a random number that will generate a random 6 digit
number.Thanks I'm still learning.
 
B

BruceM

I'm not sure what you mean by "change a random number that will generate a
random 6 digit number". However, you can use the Rnd function to generate a
random number. Why change a random number? Even if you do, how do you see
that generating another random number.
You can use the Rnd function to generate a random number. It will generate
a decimal, but you can multiply it by 1000000 to get the desired 6-digit
result (with the Format function to add leading zeros, as needed), and use
the Int function to get just the integer portion of the number. One way is
to use the form's Current event, or a command button, with something like
the following:

Me.SomeTextBox = Format(Int(Rnd()*1000000),"000000")

If you want to store the number, bind the text box to a number field in the
form's Record Source, and generate the number only for new records:

If Me.NewRecord Then
Me.SomeField = Format(Int(Rnd()*1000000),"000000")
End If

If this doesn't answer the question you need to be more specific about what
you are trying to do.
 
J

James A. Fortune

summernight said:
how do i change a random number that will generate a random 6 digit
number.Thanks I'm still learning.

tblI
ID I
1 1
2 2
3 3
4 4
....

qryRandom6Digit:
SELECT ID, Rnd(ID)*10^9 AS Seed, "0123456789" AS Digits, "123456789" AS
DigitsSans0, Seed Mod 9+1 AS Pos0, Seed Mod 10+1 AS Pos1,
Mid([DigitsSans0],[Pos0],1) AS Digit0, Mid([Digits],[Pos1],1) AS Digit1,
[Digit0] & [Digit1] & [Digit1] & [Digit1] & [Digit1] & [Digit1] AS
RandomDigits FROM tblI;

!qryRandom6digit:
ID ... RandomDigits
1 ... 269723
2 ... 417854
3 ... 580824
4 ... 661413
....

!qryRandom6digit:
ID ... RandomDigits
1 ... 740077
2 ... 459995
3 ... 699687
4 ... 904986
....

James A. Fortune
(e-mail address removed)
 

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