Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2004, 04:33 AM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default The Great ' issue (fixquotes)

Struggling to find a workaround for this sql failing.

Try inserting this to access using sql:

INSERT INTO imported(Song)
VALUES ('" & variable_song & "')

Now assume variable_song = "I don't know"

The single quote causes an error.
Now I can create a function to search and replace the offending single quote with a different character but this then affects the viewing of data in the underlying table.

Anyone know of a workaround that will let me insert this single quote?

 
Old January 31st, 2004, 07:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To force SQL to recognise that you really, really want to put a single quote into a table, replace the single quote with two single quotes:
Code:
INSERT INTO imported(Song)
VALUES ('" & replace(variable_song,"'","''") & "')

Brian Skelton
Braxis Computer Services Ltd.
 
Old January 31st, 2004, 10:29 AM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Would it not be possible to just set variable_song to "it''s my song" to do the same?

 
Old January 31st, 2004, 10:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's exactly what the Replace function does. If you prefer to do it on a seperate line:
Code:
variable_song=replace(variable_song,"'","''")

INSERT INTO imported(Song)
VALUES ('" & variable_song & "')

Brian Skelton
Braxis Computer Services Ltd.
 
Old January 31st, 2004, 12:36 PM
Authorized User
 
Join Date: Jan 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great! cooking on gas now......






Similar Threads
Thread Thread Starter Forum Replies Last Post
Great Thanks Mr. Ivor yosri_negm BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 September 4th, 2008 11:16 AM
Great book saniamirza BOOK: Accessible XHTML and CSS Web Sites: Problem Design Solution 1 March 1st, 2007 09:57 AM
This Book - Great Disappointment mhardiman BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 2 August 4th, 2006 05:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.