Advancing Numbers and Letters

D

DS

I have a field that contains a number, whenever I add another record I
want the number to go to 1A then 1B, 1C...etc. Them 1AA, 1AB etc,
Anyone know how to do this?
Thanks
DS
 
J

Jesper

I have a field that contains a number, whenever I add another record I want
the number to go to 1A then 1B, 1C...etc. Them 1AA, 1AB etc, Anyone know
how to do this?

What comes after 1ZZ ?
 
R

Ron Weiner

See if this floats your boat

Public Function NextID(strLastID As String) As String
Dim a As String

a = Right(strLastID, 1)
If a = "Z" Or IsNumeric(a) Then
NextID = UCase(strLastID & "A")
Else
NextID = UCase(Left(strLastID, Len(strLastID) - 1) & Chr(Asc(a) +
1))
End If
End Function

Put this function in a module and call it from where ever you need the next
ID

NewID = NextID(CurrentMaxID)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top