Random number initializing

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

How do I initialize the random number function to return different random
numbers for each Access session?

Thank you
Dave
 
Dave said:
How do I initialize the random number function to return different random
numbers for each Access session?


Use the Randomize statement in a procedure that runs before
you generate the random numbers.
 
This is the code that runs when a form is opened:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

This query is then run:
SELECT Table1.Num, Rnd([Num]) AS RndNo
FROM Table1;

But every time I open a new session the same random numbers appera for each
Num.

Dave
 
Dave said:
This is the code that runs when a form is opened:

Public Function RndNum(vIgnore As Variant) As Double
Static bRnd As Boolean
If Not bRnd Then
'Initialize the random number generator once only
bRnd = True
Randomize
End If
RndNum = Rnd()
End Function

This query is then run:
SELECT Table1.Num, Rnd([Num]) AS RndNo
FROM Table1;

But every time I open a new session the same random numbers appera for each
Num.


When/where do you call your RndNum function?

Or maybe you meant to call it in the query and just typed
Rnd instead??
 
Back
Top