Removing alpha characters from string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to remove alpha characters from a string, for example

wxyz 1234
w1234

Both need to return 1234.

Any ideas?
Matt
 
If the numeric part of your string has to do with the last 4 characters
then you could use: myString=Right(myString, 4)
 
Put this function in a regular module:

'********************************
'* *
'* Fxn StripAllNonNumericChars *
'* *
'********************************

' ** This function strips all nonnumeric characters from a text string.

Public Function StripAllNonNumericChars(varOriginalString As Variant) As
String
Dim blnStrip As Boolean
Dim intLoop As Integer
Dim lngLoop As Long
Dim strTemp As String, strChar As String
Dim strOriginalString As String
On Error Resume Next
strTemp = ""
strOriginalString = Nz(varOriginalString, "")
For lngLoop = Len(strOriginalString) To 1 Step -1
blnStrip = True
strChar = Mid(strOriginalString, lngLoop, 1)
For intLoop = Asc("0") To Asc("9")
If strChar = Chr(intLoop) Then
blnStrip = False
Exit For
End If
Next intLoop
If blnStrip = False Then strTemp = strChar & strTemp
Next lngLoop
StripAllNonNumericChars = strTemp
Exit Function
End Function


Then call it from the query by a calculated field:

TheNumbers: StripAllNonNumericChars([FieldName])
 

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

Back
Top