Stripping characters

  • Thread starter Thread starter John
  • Start date Start date
Well, you can setup text boxes on forms to ONLY allow numbers with a input
mask.

However, if you have existing data that you need to fix, then you can use:

Public Function OnlyNumbers(myphone As String) As String

Dim i As Integer
Dim mych As String

OnlyNumbers = ""

If IsNull(myphone) = False Then

For i = 1 To Len(myphone)
mych = Mid$(myphone, i, 1)
If InStr("0123456789", mych) > 0 Then
OnlyNumbers = OnlyNumbers & mych
End If
Next i
End If


End Function


The above function will strip all non alpha chars from a give string. You
can even do a update query on a column (make a backup before you attempt
this).

In the query buidler just type in:

update tblCustomers set FaxNum = OnlyNumbers([FaxNum]) where faxNum is not
null

-
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
 
Try using the replace function for 0 - 9 and replace it with a blank space


--
Kind regards,

Richard Bezuidenhout
email: (e-mail address removed)
mobile: +27(0)83 556 1502
fax : 0865030664
Skype: richard.bezuidenhout
you can achieve anything, if you use e-magination
 
Back
Top