As Jeff points out, two fields would be preferrable here.
The problem you will run into is finding the highest value for the field.
This is commonly done using the DMax function.
The first go round from 001A to 999A would work fine, then you would add
001B, but now every time you use the DMax, it will always return 999A because
that sorts higher than 001B. So, your options are to either reverse the
order to A001 or use two fields. The one for the number being a long integer
data type and the one for the letter a text data type. Then you could use a
routine something like this to create the next value in the series:
Function GetNextNumber() As String
Dim strHighLetter As String
Dim lngHighNumber As Long
'Find the current highest letter
strHighLetter = Nz(DMax("[SeqLetter]", "MyTable"),"A")
'Find the current highest number for the letter and add 1 to it
lngHighNumber = Nz(DMax("[SeqNumber]", "MyTable","[SeqHighLetter] = """
& strHighLetter & """"),0) + 1
'See if we need to advance to the next letter - I did not do any checking to
see
'if we go past Z. You need to figure out what to do and plan for it
If lngHighNumber > 999 Then
strHighLetter = Chr(Asc(strHighLetter) + 1)
lngHighNumber = 1
End If
'Combine them in a string and return the value
GetNextNumber = Format(lngHighNumber, "000") & strHighLetter
End Sub
--
Dave Hargis, Microsoft Access MVP
AJ said:
this should be an easy one for the gurus out there.
I need a field that increments records in the following format 123A 3
numbers and a letter. The number increment with the same letter until 999
then they need to start all over with the next letter. Then at 999Z go back
to 001A.
Such that:
123A is followed by 124A... then 999A would be followed by 001B... then 999Z
is followed by 001A.
How would this be accomplished?
Thanks so much in advance!