?
Solved

String Parsing

Posted on 2000-03-24
13
Medium Priority
?
156 Views
Last Modified: 2010-05-02
I'm adding a record to an access database using an sql action statement and I need to check that the new record entered doesn't contain a single quote ' if it does contain a single quote I need to insert another single quote beside it so the record is added without error.
How do I parse the string searching for a single quote and then insert another single quote beside it? Is there a function that does this?
PLEASE HELP!
Cheers,
M. Smith
0
Comment
Question by:Megan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +2
13 Comments
 
LVL 2

Expert Comment

by:tylerd
ID: 2654967
dim p as integer
dim newstr as string


p = 1
do until p > len(sqlstr)
     if mid(sqlstr,p,1) = "'" then
        newstr = newstr & "'"
     end if
     newstr = newstr & mid(sqlstr,p,1)
loop
------------------------------------

where sqlstr is the sql statement you want to fix
0
 
LVL 2

Expert Comment

by:tylerd
ID: 2654970
tylerd changed the proposed answer to a comment
0
 
LVL 2

Accepted Solution

by:
tylerd earned 300 total points
ID: 2654971
dim p as integer
dim newstr as string


p = 1
do until p > len(sqlstr)
     if mid(sqlstr,p,1) = "'" then
        newstr = newstr & "'"
     end if
     newstr = newstr & mid(sqlstr,p,1)
     p=p+1
loop
------------------------------------

where sqlstr is the sql statement you want to fix  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:Brendt Hess
ID: 2654978
If you are using VB6, then use the Replace function:

Replace(MyString$,"'","''")

Replaces all apostrophes with two apostrophes
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2655001
Adding to Bhess1's comment:

MyString = Replace(MyString,"'","''")

Param1 MyString = your SQL Statement
Param2 "'" = 1 single quote between 2 double quotes
Param3 "''" = 2 single quotes between 2 double quotes
0
 

Author Comment

by:Megan
ID: 2655047
Thanks to everyone. I'm going to use the replace method. :)
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2655074
In case you do not have VB6 here's a replacement for the Replace-function it works just like the one in VB6...

  Function ReplaceStr(Text As String, TextFrom As String, TextTo As String)

    Dim xStart As Long
 
    xStart = InStr(Text, TextFrom)
    Do Until (xStart = 0)
      Text = left$(Text, xStart - 1) & TextTo & Mid$(Text, xStart + Len(TextFrom))
      xStart = InStr(xStart + Len(TextTo), Text, TextFrom)
    Loop
    ReplaceStr = Text

  End Function
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2655248
Megan.. you are using the replace.. but awarding the points to the code. I think bhess1 is gonna feel a little left out.. <sigh>. If you want to change your vote, the EE community service people can help you.. <smile>. If you want to award additional points to bhess1, just leave a question with "For bhess1" in the topic. And if you don't want to do anything, thats ok to.. (just keep bhess1 away from any high precipes and / or loaded guns)... LOL.
0
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 2655291
AAA
-- aa
  |  a
  |   a
  |   a
  |   a
  |   a
  |   *bang*
  |   .
  \_*splat*__________

:)
0
 

Author Comment

by:Megan
ID: 2655313
WOW! you guys take this stuff seriously :)
I'm new at this rating answers thing (i only just joined). I didn't read fully who I was awarding the points to. SORRY bhess1!
0
 

Author Comment

by:Megan
ID: 2655321
bhess1...I have another question re vb6.
i'm posting it now. hope u can help :)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2655422
<smiling>.. its Ok Megan.. "Truth, Justice and the American Way!!!".. VB Superhero code.. <lol> and a <wink>.
0
 
LVL 32

Expert Comment

by:Brendt Hess
ID: 2661132
*groan* *moan* It's okay... I'll be out of the hospital soon... :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question