I received a Private Message from a forum participant who had:
tblComments
-Comments (text)
Given that [comments] might contain:
-" ALSF/SSALR CERTIFIED " (quotes included)
The question was (using an update query)...
...how to get rid of the double quotes and extra spacing, returning:
-ALSF/SSALR CERTIFIED
Here’s one way it might be attacked:
Query:
UPDATE tblComments SET tblComments.Comments = onespace(chopit([comments],Chr(34)));
Function ChopIt(), copied/pasted to a module, gets rid of the unwanted quotes (Chr(34))
...and Function Onespace() takes care of the excess spaces:
HTH
Bob
tblComments
-Comments (text)
Given that [comments] might contain:
-" ALSF/SSALR CERTIFIED " (quotes included)
The question was (using an update query)...
...how to get rid of the double quotes and extra spacing, returning:
-ALSF/SSALR CERTIFIED
Here’s one way it might be attacked:
Query:
UPDATE tblComments SET tblComments.Comments = onespace(chopit([comments],Chr(34)));
Function ChopIt(), copied/pasted to a module, gets rid of the unwanted quotes (Chr(34))
Code:
Function ChopIt(pStr As String, ParamArray VarMyVals() As Variant) As String
'*******************************************
'Name: ChopIt (Function)
'Purpose: Remove a list of unwanted
' characters from a string
'Inputs: From debug window:
' '? chopit("(626) 123 5555", ")","(")
'Output: 626 123 5555
'*******************************************
Dim strHold As String
Dim i As Integer, n As Integer
strHold = Trim(pStr)
'check for entry
If UBound(VarMyVals) < 0 Then Exit Function
For n = 0 To UBound(VarMyVals())
Do While InStr(strHold, VarMyVals(n)) > 0
i = InStr(strHold, VarMyVals(n))
strHold = Left(strHold, i - 1) & Mid(strHold, i + 1)
Loop
Next n
ChopIt = Trim(strHold)
End Function
...and Function Onespace() takes care of the excess spaces:
Code:
Function onespace(pStr As String)
'*******************************************
'Name: onespace (Function)
'Purpose: Removes excessive spaces from a string
'Inputs: call onespace(" the quick brown fox")
'Output: "the quick brown fox"
'*******************************************
Dim strHold As String
strHold = RTrim(pStr)
Do While InStr(strHold, " ") > 0
strHold = Left(strHold, InStr(strHold, " ") - 1) & Mid(strHold, InStr(strHold, " ") + 1)
Loop
onespace = Trim(strHold)
End Function
HTH
Bob