-----Original Message-----
If the number of digits is not fixed, and there is no fixed separator
between the letters and the numbers, then I don't see any way to do it other
than walking the string and testing each character. If the digits *always*
come at the end of the string, with no other characters between or after the
digits, we can save a few processor cycles by starting at the end of the
string and exiting as soon as we find the first non-digit:
Public Function GetDigitsFromEnd(ByVal strInput As String) As String
Const cstrDigits As String = "0123456789"
Dim lngLoop As Long
Dim strWork As String
Dim strChar As String
For lngLoop = Len(strInput) To 1 Step -1
strChar = Mid$(strInput, lngLoop, 1)
If InStr(1, cstrDigits, strChar) <> 0 Then
strWork = strChar & strWork
Else
Exit For
End If
Next lngLoop
GetDigitsFromEnd = strWork
End Function
Here's an example of how we could call this function in a query:
SELECT tblTest.TestText, GetDigitsFromEnd([TestText]) AS Digits
FROM tblTest;
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me
to use a real e-mail address in public newsgroups. E-mail replies to this
post
will be deleted without being read. Any e-mail claiming to be from brenreyn
at
indigo dot ie that is not digitally signed by me with a GlobalSign digital
certificate is
a forgery and should be deleted without being read. Follow-up questions
should
in general be posted to the newsgroup, but if you have a good reason to send
me e-mail, you'll find a useable e-mail address at the URL above.
I have a field with data that has 3 alpha and 4 numeric
characters (ex. AAA-0000) I need to create a new field
with just the numeric characters (however, the last four
are not always numeric, it could be (ex. AAA_A000)). Is
there a way to do this in Access? Thank you very much for
your help!!
.