Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate numbers / letters

Status
Not open for further replies.

jsullivan

Technical User
Jun 21, 2001
3
0
0
US
I need to generate a series of numbers automatically, each time a new record is entered. However, the series of numbers needs to always start with "CAD". It would be preferable if there is a way to include the date within the line - but I don't know how to do this. Something like "CAD6(Month)21(day)01(year)four random numbers".
I'm thinking this should be some sort of expression within a control on the form, but I'm not sure. Does anyone have a suggestion? Thank you in advance.
 
Have you tried to format the autonumber field with something like "CAD"&&&&& (where the & = a digit). The results would be CAD1, CAD 2, ... CAD1998, etc?
 
Here is a way when you click on the field it will generate what you want. Just go in design mode and right click on the field you want to do this procedure. Select properties, then go to the event page. go down to ONCLICK and click the little button with 3 dots on it. Select code and paste this procedure in. Now everytime you click on the field it will generate the desired effect. BTW the field you attach this to must be TEXT based in the table and at least 13 characters long. Hope this Helps.

Private Sub IDnumber_Click()
Dim ddate
Dim pass
Dim startcount
Dim proc
Dim a
Dim b
Dim c
Dim d
ddate = Format(Date, "Short Date")
startcount = 0

procedure1:
startcount = startcount + 1

pass = Int((9 * Rnd) + 1)
proc = Right(Str(pass), 1)

If startcount = 5 Then GoTo Endit
If startcount = 4 Then a = proc
If startcount = 3 Then b = proc
If startcount = 2 Then c = proc
If startcount = 1 Then d = proc
GoTo procedure1

Endit:
[Lastname] = "CAD" + ddate + a + b + c + d

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top