Random number generator in Access?

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

Guest

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
 
.... and you will probably want to use the Randomize statement prior to
using Rnd.

LGC
 
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
 
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
 

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

Back
Top