Random Number using Date and Time

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_
 
R

Rick Brandt

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")
 
N

nxqviet

Thanks both for the quick replies. I used the Format() function and it
looks great.

Thanks again,

V_
 

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

Top