Discussion Locked

Access97 - cleaning up data

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have data that is imported from 3rd party software. Phone #s & fed. tax id's have parentheses & hyphens in them. I need to remove the hyphens & junk from the data & return only the numbers.
How can I do this in Access? I'd like to use VB & automate the process.

Thanks for the help!

7 replies

by donq

This is a VB Function written for Access 2 or 95? that removes dashes from wherever they show up. Do the identical code removing each hyphen, or whatever you want stripped.

Good Luck. Don Q

Function RemoveDashes(CompKey As String)
'
'Description: Removes all dashes from an incoming string.
'
'Author: Don Quigg, DataByte Software Development
'
'Date: 09/28/95
'
'Revisions: NA
'

Dim tStr As String 'Assembled string
Dim txt1 As String 'Remainder of CompKey as it is processed
Dim DashPos As Integer 'Position of next Dash
Dim rLen As Integer 'Remaining length of txt1

rLen = 0
txt1 = CompKey
tStr = ""
Do
If InStr(1, txt1, "-") > 0 Then 'check for no dashes
DashPos = InStr(1, txt1, "-")
tStr = tStr & Mid$(txt1, 1, DashPos - 1)
rLen = Len(txt1) - DashPos
txt1 = Right$(txt1, rLen)
Else
If rLen = 0 Then 'either no dashes or last segment
tStr = CompKey 'no dashes, move entire key
Else
tStr = tStr & txt1 'move last segment
End If 'rLen
rLen = 0
End If 'instr
Loop Until rLen <= 0

RemoveDashes = tStr

End Function

by peyison

Here's a function that will return only the numbers in a string:

Function FixString(asSource As String) As String
Dim I As Integer
Dim sResult As String
Dim sChar As String

For I = 1 To Len(asSource)
sChar = Mid(asSource, I, 1)
If IsNumeric(sChar) Then
sResult = sResult & sChar
End If
Next

FixString = sResult

End Function

Hope this helps.

by parier

Just as easy, export to Excel and use the replace function to replace the "()" with nothing. This will remove them the reimport them to acces.

Hope this helps!

This discussion is closed to new replies.