?
Solved

Access Form VB.  Error MSG when using an apostrophe in text value via SQL

Posted on 2007-11-26
9
Medium Priority
?
235 Views
Last Modified: 2013-11-28
I am using a variable to capture the text that the user enters.  This is used in the SQL per the appropriate field and works without issue unless;  an apostrophe is used in the text.  Example:

dim variable1 as string
 
variable1 = "  hello there Sidney" - this works fine
variable1 = " hello it's Sidney" - this gives me the error.

variable1 = '" & variable1 &"' in the SQL


Thank you.
0
Comment
Question by:ellenjbr
[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
  • 4
  • 4
9 Comments
 
LVL 58
ID: 20352561
Instead of:

variable1 = '" & variable1 &"' in the SQL

  Do this:

variable1 = chr$(34) & variable1 & chr$(34)

JimD
0
 
LVL 8

Expert Comment

by:Chumad
ID: 20352608
You can also do a replace on the string to turn in the single quote into a double single quote if you want to preserve it in the database as a single quote:

variable1 = " hello it's Sidney"

'replaces all single quotes with a double-single quote
variable1 = variable1.Replace("'", "''")
0
 

Author Comment

by:ellenjbr
ID: 20352642
jimd .... it doesn't work.
0
Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

 

Author Comment

by:ellenjbr
ID: 20352790
chumad:  What you posted, is that a practical example or if not, please post one.  Thank you.
0
 
LVL 8

Expert Comment

by:Chumad
ID: 20352825
Actually, it would be practical if that were VB.NET and not Access. :)  

Let me dig a bit and look up the replace function in access. I'll post back here when I find it.
0
 
LVL 8

Expert Comment

by:Chumad
ID: 20352833
ok, here's a page that show's how to use replace in access:  http://www.techonthenet.com/access/functions/string/replace.php

One thing I'd do first though just to test this out - change your string manually to 'hello it''s sidney' (note that those are two single quotes, not a double quote). If it does indeed save for you, go ahead with the replace to find all single quotes and convert them to two single quotes.
0
 

Author Comment

by:ellenjbr
ID: 20352981
Thank you, I will look at it and get back with you.
0
 
LVL 8

Accepted Solution

by:
Chumad earned 1500 total points
ID: 20398221
Did you have any luck?
0
 

Author Comment

by:ellenjbr
ID: 20404726
hi ... not yet, this is a hectic week ... I will attempt this or next week and get back with you ... thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

762 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