Learn how to a build a cloud-first strategyRegister Now


handling glitches in sql string

Posted on 2006-05-01
Medium Priority
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!")

Question by:arichexe
1 Comment

Accepted Solution

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, "'", "''")


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