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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro or function to remove "-" from text in a field 2

Status
Not open for further replies.

DMHCCI

Vendor
May 9, 2003
22
US
I have a text field that looks like 070-71000-5400 and I would like a function or macro to remove the "-" so that the end result looks like 070710005400

Thanks
 
Do an UPDATE query. If the field is named [SOME_TEXT_FIELD], set the field to:

Replace([SOME_TEXT_FIELD],"-","")


 
If you have Access 2K or above then the Replace function can be used as in
[tt]
txtField = Replace ("070-71000-5400", "-", "")
[/tt]

If you're in Access '97 or below then use the following
[tt]
Public Function ReplaceIt(ByVal myString As String, _
ByVal strFind As String, _
ByVal strReplaceWith As String) As String
Dim n As Integer
Dim pos As Integer
Dim strTemp As String
strTemp = myString
If Len(strTemp) = 0 Then
ReplaceIt = ""
Else
pos = 1
n = InStr(pos, strTemp, strFind)
Do While n > 0
pos = n + Len(strReplaceWith)
strTemp = Left$(strTemp, n - 1) & strReplaceWith & Mid$(strTemp, n + Len(strFind))
n = InStr(pos, strTemp, strFind)
Loop
ReplaceIt = strTemp
End If
End Function
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top