Random Number using Date and Time

  • Thread starter Thread starter nxqviet
  • Start date Start date
N

nxqviet

Hi all,

I need to generate a random string to number and text on a form every
time someone open it. this string will be used as session number, which
then will be used as a criteria for other calculations using sql and
queries.

should I use a compination of Date, time, and username to generate this
random string? if yes, how do i best acheiving this? if not, what is a
better way to get this random number?

Here is what I would do, but I need to reformat the date and time so
that they appear in integer format rather than 1/2/2007 3:32 PM .....

---------------------------------
Dim varDate As Variant
Dim varTime As Variant
Dim varName As Variant
varDate = Date
varTime = Time
varName = Environ("UserName")

SessionID.Value = varDate & varTime & varName
---------------------------------


Thanks

V_
 
nxqviet said:
Hi all,

I need to generate a random string to number and text on a form every
time someone open it. this string will be used as session number, which
then will be used as a criteria for other calculations using sql and
queries.

should I use a compination of Date, time, and username to generate this
random string? if yes, how do i best acheiving this? if not, what is a
better way to get this random number?

Here is what I would do, but I need to reformat the date and time so
that they appear in integer format rather than 1/2/2007 3:32 PM .....

---------------------------------
Dim varDate As Variant
Dim varTime As Variant
Dim varName As Variant
varDate = Date
varTime = Time
varName = Environ("UserName")

SessionID.Value = varDate & varTime & varName

SessionID.Value = Format(Now(), "yyyymmddhhnnss") & Environ("UserName")
 
Thanks both for the quick replies. I used the Format() function and it
looks great.

Thanks again,

V_
 
Back
Top