'[URL unfurl="true"]http://support.microsoft.com/default.aspx?scid=kb;en-us;210433&Product=acc2000[/URL]
'Code modified
'==================================================================
' The following functions will:
' - Find the specified characters in a Text or Memo field.
' - Call another function to replace them.
'==================================================================
Function FindCarriageRepl(WhichField As String) As String
Dim intCounter As Integer
Dim strText As String
Dim intstart As Integer
intstart = 1
intCounter = 1
strText = WhichField
Do Until intCounter = 0
' Chr(13) is the Carriage character.
' Replace Chr(13) with the ANSI code for the character
' you are searching for.
intCounter = InStr(intstart, strText, Chr(13))
intstart = intCounter + 1
If intCounter > 0 And Not IsNull(intCounter) Then
strText = ReplaceCarriage(intCounter, strText)
'*********************
''--Chr(167) § /Chr(13)
'*********************
End If
Loop
FindCarriageRepl = strText
End Function
Function FindLineFeedRepl(WhichField As String) As String
Dim intCounter As Integer
Dim strText As String
Dim intstart As Integer
intstart = 1
intCounter = 1
strText = WhichField
Do Until intCounter = 0
' Chr(10) is the LineFeed character.
' Replace Chr(10) with the ANSI code for the character
' you are searching for.
intCounter = InStr(intstart, strText, Chr(10))
intstart = intCounter + 1
If intCounter > 0 And Not IsNull(intCounter) Then
strText = ReplaceLineFeeds(intCounter, strText)
'*********************
''--Chr(216) Ø /Chr(10)
'*********************
End If
Loop
FindLineFeedRepl = strText
End Function
Function FindTabsRepl(WhichField As String) As String
Dim intCounter As Integer
Dim strText As String
Dim intstart As Integer
intstart = 1
intCounter = 1
strText = WhichField
Do Until intCounter = 0
' Chr(9) is the Tab character.
' Replace Chr(9) with the ANSI code for the character
' you are searching for.
intCounter = InStr(intstart, strText, Chr(9))
intstart = intCounter + 1
If intCounter > 0 And Not IsNull(intCounter) Then
strText = ReplaceTabs(intCounter, strText)
'*********************
''--Chr(191) ¿ /Chr(9)
'*********************
End If
Loop
FindTabsRepl = strText
End Function
'==================================================================
' The following functions are called from the functions above . They
' accept two arguments, intStart and strText. The functions replace specified characters
' with characters you choose and return the updated text.
'==================================================================
Function ReplaceCarriage(intstart As Integer, strText As String) As String
' Replace % with the character you want to substitute.
'--Chr(191) ¿ /Chr(9)
'--Chr(216) Ø /Chr(10)
'--Chr(167) § /Chr(13)
Mid(strText, intstart, 1) = Chr(32) 'Chr(167)
ReplaceCarriage = strText
End Function
Function ReplaceLineFeeds(intstart As Integer, strText As String) As String
' Replace % with the character you want to substitute.
'--Chr(191) ¿ /Chr(9)
'--Chr(216) Ø /Chr(10)
'--Chr(167) § /Chr(13)
Mid(strText, intstart, 1) = Chr(32) 'Chr(216)
ReplaceLineFeeds = strText
End Function
Function ReplaceTabs(intstart As Integer, strText As String) As String
' Replace % with the character you want to substitute.
'--Chr(191) ¿ /Chr(9)
'--Chr(216) Ø /Chr(10)
'--Chr(167) § /Chr(13)
Mid(strText, intstart, 1) = Chr(32) ' Chr(191)
ReplaceTabs = strText
End Function
'==================================================================
' ' Function StripString()
'[URL unfurl="true"]http://support.microsoft.com/default.aspx?scid=kb;en-us;210227[/URL]
'Code modified
'------------------------------------------------------------------
' Returns a string minus a set of specified chars.
' Function only removes only (<> replace), may result in a long string !
'==================================================================
Function StripString(MyStr As Variant) As Variant
On Error GoTo StripStringError
Dim strChar As String, strHoldString As String
Dim i As Integer
' Exit if the passed value is null.
If IsNull(MyStr) Then Exit Function
' Exit if the passed value is not a string.
If varType(MyStr) <> 8 Then Exit Function
' Check each value for invalid characters.
For i = 1 To Len(MyStr)
strChar = Mid$(MyStr, i, 1)
Select Case strChar
'Chr(9)= Tab
'Chr(10)= LineFeed
'Chr(13)= CarriageReturn
'Chr(34)= "
'Chr(60)= <
'Chr(62)= >
Case Chr$(13), Chr$(10), Chr$(9), Chr$(34), Chr$(60), Chr$(62) 'also accepts, eg: ".", "#", ",", "-"
' Do nothing
Case Else
strHoldString = strHoldString & strChar
End Select
Next i
' Pass back corrected string.
StripString = strHoldString
StripStringEnd:
Exit Function
StripStringError:
MsgBox Error$
Resume StripStringEnd
End Function