Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to delete text a field that has numbers and text

Status
Not open for further replies.

GoingCrazy

Technical User
May 7, 2001
30
0
0
US
I'm looking for a way to delete unwanted text from a field and just show the number. The field is similar to the following:

33-12121212 switch
33-12121212-502
4bc123456 control
pressure switch

Unfortunately, there is no consistency. The part number lengths vary and not all records have text or a part number in the field. As such I can't use the Left or Right parameter because I delete numbers or add text if the parameter is too long or too short. Is there anyway to use the space between the text and numbers to act as a delimiter and delete all values after the space when it reads the space? (By the way, deleting the text manually is not an option because I am dealing with a database of thousands of entries.)

I'd appreciate any help anyone can offer.

Thanks,
GoingCrazy
 
Here is a solution you can use that will strip every non-numeric character. It will work where the built-in Val() function won't.

Public Function StripNonNumeric(txtInput As String) As String

Dim intCounter As Integer
Dim txtTemp As String

For intCounter = 1 to Len(txtInput)
Select Case Mid(txtInput, intCounter, 1)

Case "0" To "9"
txtTemp = txtTemp & Mid(txtInput, intCounter, 1)
End Select

Next

StripNonNumeric = txtTemp

End Function

Enjoy!
 
I also have a StripChars routine that may be more beneificial to you. In my routine, you are able to enter a string of characters, each of which will be stripped out of the target string. The code, with plenty of documentation, can be downloaded at
Check out the comments to see what others have had to say about my routines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top