Results 1 to 9 of 9
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    Data Count interfered with apostrophe

    When enter a last name in a form, it generates a count of the last name in the source table. The count is used to display a list of same names if count >1. It works fine except if a name has an apostrophe (like O'Briant)

    Here is the code that works fine with no apostrophe included. LN is field where enter last name.
    CountLN = DCount("[lname]", "[T_Customer]", "lname = '" & [LN] & "'")



    When last name includes a space or dash, no problem

    When the name includes an apostrophe, get this message:
    Syntax error (Missing Operator) in query expression "Lname=O'Briant"

    Any help much much appreciated.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Use Replace() and replace ' for two of the single quotes, and you should be OK?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Another way (because I don't grasp the first suggestion but that's probably on me. Seems like the suggestion is to count O'Brien as O''Brien which shouldn't work?)
    Code:
    DCount("[lname]", "[T_Customer]", "[lname]= " & Chr(34) & [LN] & Chr(34))
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    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,722
    The procedure of doubling up on the single quote is called escaping the quote (or at least it used to be).
    Just replace a single quote with 2 single quotes and all will be well.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Cross posted even after responses here
    https://www.access-programmers.co.uk...trophe.318152/
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Thanks much. Works and simpler than another reply that I got. Thanks again.

  7. #7
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I think that I answered the wrong message. Your way works just fine. Simpler than the one I got from another site. Thanks very much.

    I can't figure out how to mark this as solved. Will do as soon as I can.

  8. #8
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I replid to wrong solution. You are right, I got the reply from the English site and worked well. They responded before This site.

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Quote Originally Posted by gg80 View Post
    I replid to wrong solution. You are right, I got the reply from the English site and worked well. They responded before This site.
    Thanks for informing everyone who tried to help you, that they were wasting their time. I'm sure they had nothing better to do. I would advise you to read the following link about the etiquette of cross-posting: https://www.excelguru.ca/content.php?184
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. apostrophe in dcount value
    By newbieX in forum Programming
    Replies: 3
    Last Post: 06-08-2018, 09:43 AM
  2. apostrophe misery
    By dgmdvm in forum Forms
    Replies: 16
    Last Post: 03-23-2017, 05:47 PM
  3. Issues using apostrophe
    By rosscortb in forum Access
    Replies: 5
    Last Post: 02-05-2015, 11:34 AM
  4. Apostrophe in name
    By NISMOJim in forum Programming
    Replies: 1
    Last Post: 04-04-2013, 10:14 PM
  5. Replies: 2
    Last Post: 02-16-2012, 04:29 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