After importing the data into a Access table I need to format (clean) a Memo field as it has some odd characters and cr/lf also.
The code I have been using to do this is shown below, my question is they must be a better way of doing this
Note the input (Instring) is the Memo field to be cleaned.
Private Sub CleanField(Instring As String)
Dim I As Integer
Dim length As Integer
Modified = False
length = Len(Instring)
If length > 0 Then
For I = 0 To length - 1
char = Asc(Mid(Instring, I + 1, 1))
If char < 21 Or char > 126 Then
Outstring = Outstring & " "
Modified = True
intRecChanged = intRecChanged + 1
Else
Outstring = Outstring & Chr(char)
End If
Next I
End If
'Debug.Print Outstring
If Modified Then
' If we have replaced special characters with spaces, then need to remove extra spaces now
Instring = Replace(Instring, " ", " ")
Instring = Replace(Instring, " ", " ")
Instring = Replace(Instring, " ", " ")
Instring = Replace(Instring, " ", " ")
End If
Instring = Outstring
End Sub
The code I have been using to do this is shown below, my question is they must be a better way of doing this
Note the input (Instring) is the Memo field to be cleaned.
Private Sub CleanField(Instring As String)
Dim I As Integer
Dim length As Integer
Modified = False
length = Len(Instring)
If length > 0 Then
For I = 0 To length - 1
char = Asc(Mid(Instring, I + 1, 1))
If char < 21 Or char > 126 Then
Outstring = Outstring & " "
Modified = True
intRecChanged = intRecChanged + 1
Else
Outstring = Outstring & Chr(char)
End If
Next I
End If
'Debug.Print Outstring
If Modified Then
' If we have replaced special characters with spaces, then need to remove extra spaces now
Instring = Replace(Instring, " ", " ")
Instring = Replace(Instring, " ", " ")
Instring = Replace(Instring, " ", " ")
Instring = Replace(Instring, " ", " ")
End If
Instring = Outstring
End Sub