-
Generating Random Number/ID
I am wondering if someone can lend me a hand. I am trying to create a random Id using letters, dates and random letters/numbers to look like this:
B = Random Letter
20051103 = Current Year, Month, Day
1T4SZ = Random Letters and Numbers
B200511031T4SZ is how it would look when it is entered into my table.
I am struggling on how to do this.
Can someone lend me a hand on how to create this?
Basically I will update this field up my update to my table from a form.
I am writing this back to an Access Database. I need help generating the Id and the concanation.
Thanks for any help that can be provided.
-
to generate a random letter "A" to "Z"
chr(65+fix(rnd*26))
a random number "0" to "9"
chr(48+fix(rnd*10))
to format the date:
format(date,"yyyymmdd")
Marco
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
While I am looking at this I see you ended this with the word Macro.
Why Macro? I have not seen that before? I have tried writing this and I seem to be having some issues.
Basically when I put this in my form load to populate my text box I am not getting any thing to work.
I thank you for your help.
-
Read it again: it is MARCO, and that is my name. I like to sign my posts 
You are welcome.
Marco
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
Thanks and my apologies. I am at work early and guess my reading is not all that great. Here is what I ended up doing to create my number:
Public Function GenPrimaryValue() as String
CrntDate = Now
upperbound = 89
lowerbound = 65
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")
strEnd = ""
For X = 1 To 5
upperbound = 0
lowerbound = 2
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
Select Case intChar
Case 1
upperbound = 89
lowerbound = 65
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
Case Else
upperbound = 56
lowerbound = 48
intChar = CInt((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Select
strEnd = strEnd & Chr(intChar)
Next X
GenPrimaryValue = strStart & strDate & strEnd
Similar Threads
-
Replies: 3
Last Post: 10-12-2005, 01:35 AM
-
By Suze in forum VB Classic
Replies: 2
Last Post: 05-10-2005, 03:41 PM
-
By ozmanbozman in forum C++
Replies: 25
Last Post: 02-17-2005, 06:39 AM
-
Replies: 3
Last Post: 05-14-2002, 08:04 PM
-
Replies: 2
Last Post: 04-30-2001, 03:08 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks