Solved

String Parsing

Posted on 2000-03-24
13
152 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 100 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 32

Expert Comment

by:bhess1
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:bhess1
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:bhess1
ID: 2661132
*groan* *moan* It's okay... I'll be out of the hospital soon... :)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 61
How to produce a SHA-1 hash function in vb6 in order to save it to a table 8 64
Assign a value in Excel V-Basic 3 30
Macro problems with Excel file 6 27
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

730 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