Random number generator in Access?

J

J_eddy

Looking for way to generate random numbers from a range given by the user.
We built something back in school to do this, but it wasn't in Microsoft
Access. (Using currently Access 2000)...........thanks
 
J

J_eddy

So now that I am armed with this bit of code.............can you assist me in
building a query/form combination that would work nicely with it ??
thanks
 
A

Alex White MCDBA MCSE

3 textboxes on the form txtLower, txtUpper, txtResult and a button called
cmdGenerate

Private Sub cmdGenerate_Click()
Randomize
If IsNumeric(Me.txtLower.VALUE) And IsNumeric(Me.txtUpper.VALUE) Then
Me.txtResult.VALUE = (Val(Me.txtUpper.VALUE) -
Val(Me.txtLower.VALUE) + 1) * Rnd + Val(Me.txtLower.VALUE)
End If
End Sub

to get an integer value

Private Sub cmdGenerate_Click()
Randomize
If IsNumeric(Me.txtLower.VALUE) And IsNumeric(Me.txtUpper.VALUE) Then
Me.txtResult.VALUE = Int((Val(Me.txtUpper.VALUE) -
Val(Me.txtLower.VALUE) + 1) * Rnd + Val(Me.txtLower.VALUE))
End If
End Sub




I don't know specificly what you are trying to achieve but the firstcode
will generate a floating point number between the lower and higher number,
the second will produce an integer value
 
Top