We rarely get 26 calls in one day.
"Rarely" is the bane of my existance in such cases. What will you do
when you need to get "On Beyond Zebra"? Just discard the information
on those last two calls on the busy day?
This is the Number assigned to all cases.
It needs to be unique and this is how the company I am doing the work for
would like to number them. I will talk to them about the limitation. I
tested seperating the fields into 3. First field contains the CE, second
field contains the date, and the third contains the A, B, C, etc. I ran into
two problems.
Ok... if you insist. You asked:
I want it to always start with CE
Then I want it to be the date listed as yymmdd format without the /
Then I want it to assign an "A" after that example CE041026-A then
CE041026-B and so on.
In the Form's BeforeInsert event (and yes, you MUST use a form; table
datasheets don't have usable events) click the ... icon and invoke the
code builder. Edit the code to something like this (I'm assuming your
table is named MyTable, your field named CaseNumber, and the form
control named txtCaseNumber - change these as appropriate):
Private Sub Form_BeforeInsert(Cancel as Integer)
Const strAlpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!!"
Dim strCaseNumber As String
Dim strLetter As String
Dim vPrevious As Variant
' Set up the constant and date portion of the code
strCaseNumber = "CE" & Format(Date, "yymmdd") & "-"
' find the largest existing code for this day, if any
vPrevious = DMax("[CaseNumber]", "[MyTable]", _
"[CaseNumber] LIKE " & strCaseNumber & "*")
If IsNull(vPrevious) Then
' first call of the day, use A
strCaseNumber = strCaseNumber & "A"
Else
' later call, find the last letter
strLetter = Right(vPrevious, 1)
strCaseNumber = strCaseNumber & _
Mid(strAlpha, InStr(strAlpha, strLetter) + 1, 1)
End If
Me!txtCaseNumber = strCaseNumber
End Sub
This will assign CE041027-! to the 27th and all later calls; this will
cause an error if (as you should) you have CaseNumber as your table's
primary key. In a professional app I'd use error trapping to handle
this but this should at least get you started.
John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps