Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

564 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