Results 1 to 3 of 3
  1. #1
    crowegreg is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    398

    Insert statement

    Within VBA behind a form, I have the following statements:



    strinsert = "INSERT INTO [tblExportMSR] ( [Title], [ISBN 13], [Series #], [Quantity]) values (" & "'" & strbName & "'" & "," & "'" & strbISBN13 & "'" & "," & "'" & strbSeries & "'" & "," & "'" & strbOrderQty & "'" & ")"

    DoCmd.RunSQL strinsert

    This works perfectly until one of the values within one of the variables contains a '. An Example is:
    strbname = NH Trees & W'flowers

    I can't figure out what the syntax should be. Thanks for your assistance!!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    21,909
    Here's a tutorial that covers that possibility:

    http://www.baldyweb.com/BuildSQL.htm

    In short you can use Chr$(34) instead of the quotes you're using.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,443
    strinsert = "INSERT INTO [tblExportMSR] ( [Title], [ISBN 13], [Series #], [Quantity]) values (""" & strbname & """,""" & strbisbn13 & """, """ & strbseries & """,""" & strborderqty & """)"

    In Access you can use " and ' marks to indicate text, if you have fields with a ' mark in them it's going to confuse access and it's going to think there's another field so just use the " mark instead.

    EDIT you have to use double "" marks to indicate a single " mark in a text string.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Help about access INSERT INTO statement
    By ducthang88 in forum Programming
    Replies: 7
    Last Post: 12-03-2010, 08:40 AM
  3. Insert Into Statement with Line Numbers
    By Cheshire101 in forum Programming
    Replies: 1
    Last Post: 10-11-2010, 02:53 PM
  4. Replies: 4
    Last Post: 09-03-2010, 02:55 PM
  5. Syntax Error In Insert Into Statement
    By frankvfox in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 12:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums