Results 1 to 5 of 5
  1. #1
    estelle1966 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    7

    Question Insert Into Statement & strings with special characters

    I am creating a new record in a table in Access 2016, using data that the user has input in various forms. I'm picking up a problem with special characters in the user input - for instance, today's input was "Pack in 100's" - the apostrophe caused havoc with the INSERT INTO statement, causing it to crash with a syntax error.

    It doesn't Is there any way to "wrap" the user input string so that SQL ignores whatever it contains? I'm thinking something like using # to identify a date?

    TIA

  2. #2
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    257
    Show insert SQL statement.

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    use either dbl quotes ", or single ', but you cant use both.
    I use double as the outer enclosure, but before you put it in the sql, use REPLACE to change any doubles in the string to single,
    THEN you can sql.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If this were a textbox bound to field, the apostrophes and quotes would not be an issue. Why using INSERT statement?

    Since user won't know about doubling apostrophes, use Replace function:
    Code:
    Replace(textboxname, "'", "''")
    An alternative that also will not have issue with apostrophe or quote marks, is to open recordset and use recordset AddNew and Update methods to create record.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Using Replace() for special characters
    By RayMilhon in forum Programming
    Replies: 2
    Last Post: 01-07-2017, 02:44 PM
  2. Replies: 3
    Last Post: 05-09-2015, 06:40 PM
  3. Search for special characters
    By davej311 in forum Queries
    Replies: 3
    Last Post: 11-20-2013, 02:35 PM
  4. Need to delete special characters
    By tlrutledge in forum Queries
    Replies: 1
    Last Post: 08-23-2013, 03:10 AM
  5. Special Characters
    By orgelizer in forum Access
    Replies: 0
    Last Post: 03-20-2007, 08:24 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