Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping out specific characters 2

Status
Not open for further replies.

mickeyg

Technical User
Mar 30, 2001
120
US
I have two tables in a query linked by a field that contains character data such as 14 1/2.

One of the tables is an imported table where the user might have data such as 14 1/2".

How do I strip out the single and double quotation marks in my criteria?

Thanks,
Mickey

 
Toughie.

I can only think to do this with a "walk" through the string.

This is my (query SQL.
SELECT tblInches.Inches, basRemoveQuote([Inches]) AS INW_O_Quo
FROM tblInches;



This is the Results. The first col is the source, the second is the result.

Inches INW_O_Quo

"4 1/2""" 4 1/2
"37.6""" 37.6
4 4
121 121
"7 1/4""" 7 1/4
"8' 4 3/4 """ 8' 4 3/4


This is the function:
Code:
Public Function basRemoveQuote(StringIn As String) As String

    Dim Idx As Integer
    Dim strChr As String
    Dim strReplace As String

    For Idx = 1 To Len(StringIn)
        strChr = Mid(StringIn, Idx, 1)
        If (strChr <> Chr(34)) Then
            strReplace = strReplace & strChr
        End If
    Next Idx

    basRemoveQuote = strReplace


End Function

hopefullly you can see how to use this in an UPDATE query.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
I am looking to remove anything that is not a number or the slash mark from the data.

Basically this is an update query where my criteria is tblImport.Weight = tblConv.Length. Then I update tblImport to the matching tblConv.Weight field.

Maybe I need to run a data massaging query before I run this update query.

Mickey
 
Public Function basRemoveQuote(StringIn As String) As String

Dim Idx As Integer
Dim strChr As String
Dim strReplace As String

For Idx = 1 To Len(StringIn)
strChr = Mid(StringIn, Idx, 1)
If (IsNumeric(strChr) Or MyChr = &quot;/&quot;) Then
strReplace = strReplace & strChr
End If
Next Idx

basRemoveQuote = strReplace


End Function



MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Thanks Michael.

I will give that a shot.

Mickey
 
Would the Val function work in this context? If all of the values are ostensibly numeric it might be able to reduce them to the Single/Double value that the string represents.
 
No. Val will stop at the first non-numeric char.

MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top