K
Kenny G
Hello,
I need some help on generating a number with an update query. I have run
the query and the query runs and will generate a random number each time I
run the query. I'd like to have the numbers generated with only one click.
The below code is in a mod and the reference to the mod is in the query. I
was told I need some loop or do until code in this. Any help would be
appreciated.
Public Function GenPrimaryValue() As String
Dim strStart As String
Dim strDate As String
Dim strEnd As String
Dim CrntDate As Date
Dim intChar As Integer
Dim upperbound As Long
Dim lowerbound As Long
Dim X As Long
Randomize
CrntDate = Now
upperbound = 65
lowerbound = 89
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
strStart = Chr(intChar)
strDate = DatePart("YYYY", CrntDate)
strDate = strDate & Format(DatePart("m", CrntDate), "00")
strDate = strDate & Format(DatePart("d", CrntDate), "00")
strDate = strDate & Format(DatePart("n", CrntDate), "00")
strDate = strDate & Format(DatePart("s", CrntDate), "00")
strEnd = ""
For X = 1 To 5
upperbound = 0
lowerbound = 4
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
Select Case intChar
Case 1
upperbound = 65
lowerbound = 89
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
Case Else
upperbound = 51
lowerbound = 48
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Select
strEnd = strEnd & Chr(intChar)
Next X
GenPrimaryValue = strStart & strDate & strEnd
PRONUM = GenPrimaryValue
End Function
I need some help on generating a number with an update query. I have run
the query and the query runs and will generate a random number each time I
run the query. I'd like to have the numbers generated with only one click.
The below code is in a mod and the reference to the mod is in the query. I
was told I need some loop or do until code in this. Any help would be
appreciated.
Public Function GenPrimaryValue() As String
Dim strStart As String
Dim strDate As String
Dim strEnd As String
Dim CrntDate As Date
Dim intChar As Integer
Dim upperbound As Long
Dim lowerbound As Long
Dim X As Long
Randomize
CrntDate = Now
upperbound = 65
lowerbound = 89
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
strStart = Chr(intChar)
strDate = DatePart("YYYY", CrntDate)
strDate = strDate & Format(DatePart("m", CrntDate), "00")
strDate = strDate & Format(DatePart("d", CrntDate), "00")
strDate = strDate & Format(DatePart("n", CrntDate), "00")
strDate = strDate & Format(DatePart("s", CrntDate), "00")
strEnd = ""
For X = 1 To 5
upperbound = 0
lowerbound = 4
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
Select Case intChar
Case 1
upperbound = 65
lowerbound = 89
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
Case Else
upperbound = 51
lowerbound = 48
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Select
strEnd = strEnd & Chr(intChar)
Next X
GenPrimaryValue = strStart & strDate & strEnd
PRONUM = GenPrimaryValue
End Function