[AccessD] How to Eliminate a Numeric String from a Field in anAccess Query

Gustav Brock gustav at cactus.dk
Thu May 17 02:31:00 CDT 2012


Hi Arthur

Given the examples, Split could do it:

strFirst = Split(strValue, " ")(0)

/gustav


>>> fuller.artful at gmail.com 17-05-12 0:03 >>>
Jim,

That's only going to work for one specific example. But assuming that your
examples are accurate, that is, an indefinite number of alpha chars are
perhaps followed by an indefinite number of numeric chars, then the
following should work:

<vba>
Public Function AlphaPart(s As String)
    Dim i As Integer
    Dim j As Integer
    Dim strAlphaPart As String
    j = Len(s)
    For i = 1 To j
        Debug.Print Mid(s, i, 1), IsNumeric(Mid(s, i, 1))
        If IsNumeric(Mid(s, i, 1)) Then  'Bingo!
            strAlphaPart = Left(s, i - 1)
            Exit For
        End If
    Next
    AlphaPart = strAlphaPart
End Function

Example:
? AlphaPart("Arthur 123")
'returns "Arthur"

I tested it against a few strings and it seems to work as advertised.
HTH,

-- 
Arthur
Cell: 647.710.1314

Prediction is difficult, especially of the future.
  -- Niels Bohr



More information about the AccessD mailing list