Hi Rob
I can't imagine a situation where you would want 24A to be the natural
sequitur from 23Z. Maybe 23AA or something.
My point is that I see this as two separate entities - a number and a
suffix/subletter/revisioncode/whatever. In that respect, they belong in
separate fields. Defining an arbitrary end to the range of suffixes,
which causes the main number to increment, makes no sense to me.
--
Cheers,
Graham Mandeno [Access MVP]
Auckland, New Zealand
I put together the complete code that you will need. Here is a sample of
the output:
Starting value is: 23W
Next value is: 23X
Next value is: 23Y
Next value is: 23Z
Next value is: 24A
Next value is: 24B
Next value is: 24C
Next value is: 24D
The subprocedure TestProcess() is what I used as the starting point.
The starting value was toward the end so that I knew it would have to
rollover to a new number and letter.
Let me know if you find any kinks in it and also how it worked out for
you.
Rob
Here's the code to do it:
Option Compare Database
Option Explicit
Private Const mstrLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Public Sub TestProcess()
Dim strValue As String
Dim x As Integer
Dim lngNumber As Long
Dim strChar As String
strValue = "23W"
Debug.Print "Starting value is: " & strValue
' display next 7 entries
For x = 1 To 7
lngNumber = GetNumericValue(strValue)
strChar = GetNextLetter(strValue)
If strChar = "A" Then
lngNumber = lngNumber + 1
End If
strValue = CStr(lngNumber) & strChar
Debug.Print "Next value is: " & strValue
Next x
End Sub
' Comment: Extract the numeric value
Public Function GetNumericValue( _
ByVal strValue As String) As Long
' The Val function stops reading the string at the first character it
can't
' recognize as part of a number. Symbols and characters that are often
' considered parts of numeric values, such as dollar signs and commas,
are
' not recognized. However, the function recognizes the radix prefixes
&O
' (for octal) and &H (for hexadecimal). Blanks, tabs, and linefeed
characters
' are stripped from the argument.
GetNumericValue = Val(strValue)
End Function
' Comment: Extract the character value
Public Function GetCharValue( _
ByVal strValue As String) As String
Dim strNumericValue As Long
strNumericValue = CStr(GetNumericValue(strValue))
GetCharValue = Trim(Replace(strValue, strNumericValue, "", 1, ,
vbTextCompare))
End Function
Public Function GetNextLetter( _
ByVal strValue As String) As String
Dim strCurrentChar As String
Dim strReturnValue As String
Dim intCurrentCharPosition As Integer
strCurrentChar = GetCharValue(strValue)
If strCurrentChar = "Z" Then
strReturnValue = "A"
Else
intCurrentCharPosition = InStr(1, mstrLetters, strCurrentChar,
vbTextCompare)
strReturnValue = Mid(mstrLetters, intCurrentCharPosition + 1, 1)
End If
GetNextLetter = strReturnValue
End Function
--
FMS Professional Solutions Group
http://www.fmsinc.com/consulting
Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com
FMS Advanced Systems Group
http://www.fmsasg.com/
How do you increment a mixed field....
Lets say 7A to 7B etc..
or 15A to 15B etc...
or 178A to 178B etc...
I know that there is a MID() function but I'm umder the impression
that you have to know how many fields you have to count over. Any
help appreciated, Thanks
DS