Stripping Characters in a String

  • Thread starter Thread starter Joe
  • Start date Start date
hi,

how can i remove all characters from a string, except numeric ones?

thx

Copy and paste this into a new Module, and save it as basEcdysiast:

Public Function DigitsOnly(strIn As String) As String
Dim iPos as Integer
Dim strChar As String
DigitsOnly = ""
For iPos = 1 to Len(strIn)
strChar = Mid(strIn, iPos, 1)
If IsNumeric(strChar) Then
DigitsOnly = DigitsOnly & strChar
End If
Next iPos
End Function

You can then run an Update query updating your mixed field to

DigitsOnly([fieldname])

if it's a field in a table that you're trying to strip.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
hi,

how can i remove all characters from a string, except numeric ones?

thx

Create a User Defined function and call it from a query.

Copy and Paste this below code into a Module:

Public Function FindAllNumbers(strString As String)
On Error GoTo Err_Handler

Dim intX As Integer
Dim intY As Integer

For intX = 1 To Len(strString)
intY = Asc(Mid(strString, intX, 1))
If intY >= 48 And intY <= 57 Then
FindAllNumbers = FindAllNumbers & Chr(intY)
End If
Next intX

Exit_FindAllNumbers:
Exit Function
Err_Handler:
Resume Exit_FindAllNumbers
End Function
==============
In the query, add a new column:
JustNumbers:FindAllNumbers([FieldName])
 
thx very much ;o)




hi,

how can i remove all characters from a string, except numeric ones?

thx

Copy and paste this into a new Module, and save it as basEcdysiast:

Public Function DigitsOnly(strIn As String) As String
Dim iPos as Integer
Dim strChar As String
DigitsOnly = ""
For iPos = 1 to Len(strIn)
strChar = Mid(strIn, iPos, 1)
If IsNumeric(strChar) Then
DigitsOnly = DigitsOnly & strChar
End If
Next iPos
End Function

You can then run an Update query updating your mixed field to

DigitsOnly([fieldname])

if it's a field in a table that you're trying to strip.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top