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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with MID function not working as expected 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I want to replace certain characters with a space or nothing. But when the code gets to Case "'", "(", ")"
it does nothing it does not replace a single quote with nothing it leaves it alone.
so the string still has a single quote in it.
My Dog's house
becomes
My_Dog's_house
I need it to be
My_Dogs_house (no single quote)

here is my code
Code:
    For a = 1 To Len(data1)
        Select Case Mid(data1, a, 1)
            Case " ", "#", "&"
                Mid(data1, a, 1) = "_"
            Case "'", "(", ")"
                Mid(data1, a, 1) = ""    'single quote: remove and put nothing
        Case Else
            'do nothing, characters are normal
        End Select
    Next

TIA

DougP, MCP, A+
[r2d2]
I love this site and all you folks that helped me over the years!
 
why not use the REPLACE function instead?

I would look up the exact syntax, except due to licensure reconciliations I don't have Access on my PC anymore!

I think it would be:
Code:
Replace(data1, "'", "")

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
The Mid function retrieves values, it doesn't insert them.

The following

Mid(data1, a, 1) = "_"

merely equates to True or False, it does nothing to data1.


 
Joe, you confuse the Mid instruction with the Mid function.
 
Huh, never knew there was a Mid statement as well as a Mid function. Somehow it just doesn't seem like a good idea to have the same names for two different things in a programming language.


 
Anyway, to remove a character, replace this:
Mid(data1, a, 1) = ""
with this:
data1 = Left(data1, a - 1) & Mid(data1, a + 1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top