Randomly generate a Code

Posted on 2003-03-29
Medium Priority
Last Modified: 2010-05-01
as the topic, how to use a command buttom randomly generate a ID(including letter and number), and then store it in MS access DB, and all the ID must unique!
Question by:Barca
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 8230614
OK, here is my idea, use the current time along with some other random letters

Private sub command1_Click()
    dim code as string
    code = GetCode()
    ' now save the code to database...
End sub

Private Function GetCode() As String
    Dim i As Long
    Dim c As Long

    c = Int(Rnd(1) * 5) + 1
    For i = 0 To c
        GetCode = GetCode & Chr(Int(Rnd(1) * 26) + Asc("a"))
    Next i
    GetCode = GetCode & Format(Now, "YYYYMMDDHHNNSS")
    c = Int(Rnd(1) * 5) + 1
    For i = 0 To c
        GetCode = GetCode & Chr(Int(Rnd(1) * 26) + Asc("a"))
    Next i
End Function
LVL 12

Accepted Solution

jyokum earned 60 total points
ID: 8231014

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question