To be placed automatically random numbers in TextBoxes

diakis

Registered User.
Local time
Today, 07:37
Joined
Jul 4, 2006
Messages
16
Not having much knowledge about codes, I’m trying to make in ACCESS 2003 a form “fr1” with 4 TxtBox s1, s2, s3 and s4 in which I want to be placed automatically random numbers ranging from 1 up to 6.
The code I believe that is suitable for this is the one below:
Function YP4()
Randomize
Dim fr As Form
Dim n As Integer
Set fr = Forms("fr1")
For n = 1 To 4
fr! {"s" + Str(n)} = Int((6 * Rnd) + 1)
Next n
End Function
The part that is in big brackets, and which is the name of the TxtBox, {“s” + Str (n)}, is the one that I don’t know how to make.
Could somebody help me with this?
Please take into account that perhaps instead of 4 I may need 10 or even 20 random numbers, therefore I would like to skip the loop n = 1 to…
Thank you in advance!
 
For n = 1 To 4
fr! {"s" + Str(n)} = Int((6 * Rnd) + 1)
Next n

you'll need something like this:
PHP:
For n = 1 To 6
randomize
mynumber = int((6 * Rnd) + 1)
forms("fr").controls("s" & cstr(n)) = mynumber
Next n
if you want uniques, you'll of course have to check to see if you've used the numbers youre getting already
 
It works. Thank you ajetrumpet
 

Users who are viewing this thread

Back
Top Bottom