Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

handling glitches in sql string

Posted on 2006-05-01
1
Medium Priority
?
295 Views
Last Modified: 2010-05-01
I need to include glitches within a query string, but keep getting an "unterminated string" error.  How would I modify the below to accept glitches within the Name field?

Set conn = CreateObject("ADODB.Connection")
conn.Open MSSqlConnStr

MyName = "O'Brien"

MySql = "SELECT * FROM MyTable WHERE Name = '" & MyName & "'"

Set rs = conn.Execute(MySql)

If Not rs.EOF Then MsgBox("Found Name!")

rs.Close
conn.Close
0
Comment
Question by:arichexe
1 Comment
 
LVL 9

Accepted Solution

by:
dancebert earned 400 total points
ID: 16581568
Is your back end Sql Server?  From the documentation:

When using single quotation marks to delimit a character constant that
contains an embedded single quotation mark, use two single quotation marks
to represent the embedded single quotation mark.

For example,
MyName= replace(MyName, "'", "''")

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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

810 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