Results 1 to 4 of 4

apostrophe in dcount value

  1. #1
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    111

    apostrophe in dcount value

    The following statement bombs when the StoreName value has an apostrophe in it. How can I modify this statement to accept these values?



    Code:
    If DCount("StoreName", "Stores", "StoreName = '" & Me.txtStoreName.Value & "'") > 0 Then
    I always get turned around on these darn characters.

    Thank you in advance

    Access 2010

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    6,446
    Don't use a single quote,instead use double:

    const Q = """"

    "[field]=" & Q & me.txtBox & Q

  3. #3
    Ajax is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    5,658
    use the replace function to replace one single quote with two - it's commonly used for names like O'Leary etc

    ………."StoreName = '" & replace(Me.txtStoreName.Value,"'","''") & "'")

  4. #4
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    111
    I went with Ajax's solution because it conveyed in the code what I was trying to do better. Thank you both for responding.

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

Similar Threads

  1. Syntax Error when using Apostrophe
    By PicoTTS in forum Access
    Replies: 4
    Last Post: 06-27-2017, 06:26 PM
  2. apostrophe misery
    By dgmdvm in forum Forms
    Replies: 16
    Last Post: 03-23-2017, 04:47 PM
  3. Error 3077 - use of apostrophe
    By dotcanada in forum Access
    Replies: 6
    Last Post: 08-11-2016, 11:21 AM
  4. Issues using apostrophe
    By rosscortb in forum Access
    Replies: 5
    Last Post: 02-05-2015, 10:34 AM
  5. Apostrophe in name
    By NISMOJim in forum Programming
    Replies: 1
    Last Post: 04-04-2013, 09:14 PM

Tags for this Thread

Posting Permissions

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