Results 1 to 5 of 5
  1. #1
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29

    Syntax Error when using Apostrophe

    Hi,

    I have a formula in a query that tries to sum up all the values whenever the description matches. It works great except whenever the description contains an apostrophe and then I get syntax errors.

    Is there any ways around this?

    Quantity_Released: DSum("Quantity","Product Query","Description = '" & [Description] & "'")

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Done use Dsum, instead use a query that does the Sum.
    no apostrophe error.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,413
    you need to replace the single quote with two single quotes using the replace function

    ......"Description = '" & replace([Description],"'","''") & "'"

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    And if there is a quote mark in the text, really a nuisance. I do whatever I can to prevent use of quote marks in data, such as not using " to represent inches. Not if you intend to reference the field in any VBA code, as in your situation.
    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.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    And note that "Description" is a reserved word in Access and shouldn't be used as an object name. Plus it is not very descriptive......

    May change to something like "ProblemDesc", "GroupDesc", "TreatmentDesc", etc.......

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

Similar Threads

  1. Error 3077 - use of apostrophe
    By dotcanada in forum Access
    Replies: 6
    Last Post: 08-11-2016, 12:21 PM
  2. Replies: 2
    Last Post: 04-14-2014, 10:42 PM
  3. Replies: 5
    Last Post: 09-05-2012, 09:28 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM

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