lawsonbooth
10-15-2009, 10:23 AM
I have the following code and I cannot get it to work - any help would be greatly appreicated.
I am trying to look for all of a given character and replace them with nulls
so that the characters in the string will all be run together.
Example: Columbus, GA, XXXX would be ColumbusGAXXXX
vB code
Option Compare Database
Option Explicit
Sub DoRemoveComma()
Dim x As String
Dim xSourceStr
Dim oDB As Database
Dim oRst As Recordset
Set oDB = CurrentDb()
Set oRst = oDB.OpenRecordset("AddrLine")
oRst.MoveFirst
xSourceStr = oRst![line1]
x = CharReplace(xSourceStr, ",", vbNullString)
End Sub
Public Function CharReplace(ByVal xStr As String, ByVal xFindChar As String, ByVal xReplChar As String) As String
Dim xlen
Dim n As Long
xlen = Len(xStr)
For n = 1 To xlen
If Mid(xStr, n, 1) = xFindChar Then
Mid(xStr, n, 1) = xReplChar
End If
Next n
'CharReplace = xStr
End Function
Lawson
I am trying to look for all of a given character and replace them with nulls
so that the characters in the string will all be run together.
Example: Columbus, GA, XXXX would be ColumbusGAXXXX
vB code
Option Compare Database
Option Explicit
Sub DoRemoveComma()
Dim x As String
Dim xSourceStr
Dim oDB As Database
Dim oRst As Recordset
Set oDB = CurrentDb()
Set oRst = oDB.OpenRecordset("AddrLine")
oRst.MoveFirst
xSourceStr = oRst![line1]
x = CharReplace(xSourceStr, ",", vbNullString)
End Sub
Public Function CharReplace(ByVal xStr As String, ByVal xFindChar As String, ByVal xReplChar As String) As String
Dim xlen
Dim n As Long
xlen = Len(xStr)
For n = 1 To xlen
If Mid(xStr, n, 1) = xFindChar Then
Mid(xStr, n, 1) = xReplChar
End If
Next n
'CharReplace = xStr
End Function
Lawson