Function to remove all characters which are not 'allowed' from a string.
Function CleanString(strOneLine As String) As String
Dim I As Integer
Dim strOutLine As String
Dim strOneChar As String
Dim strAllowed As String
'---------------------------------------------------
'- Set up a string of allowed characters. In this -
'- case, A to Z and a to z plus single quote ' -
'---------------------------------------------------
strAllowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'"
'---------------------------------------------------
'- If an empty string is passed to the function, -
'- just exit. -
'---------------------------------------------------
If strOneLine = "" Then
strOutLine = ""
Exit Function
End If
'---------------------------------------------------
'- Build an output string containing the valid -
'- characters from the input string -
'---------------------------------------------------
For I = 1 To Len(strOneLine)
strOneChar = Mid$(strOneLine, I, 1)
If InStr(strAllowed, strOneChar) > 0 Then
strOutLine = strOutLine & strOneChar
End If
Next I
CleanString = strOutLine
End Function