Results 1 to 15 of 15
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    best way to include quote in field

    Hi,


    I'm in the process of creating a database for medicinal plants of the Middle East and need to include the phonetic version of Hebrew and Arabic names, these phonetic names are very often hyphenated to indicate pronunciation.
    I'm using Access tables and forms to check and edit this data and was wondering if there's any way to work with strings that include a single quote?
    Such as replacing the quote with a special character that doesn't cause problems and returning that quote when you need to display the field.

    Thanks for any help
    David

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Here is a list of special characters that you cannot use, select one that is not on this list: https://support.office.com/en-us/art...__toc272229039

  3. #3
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi aytee111, Thanks for your reply, I wanted to know the best way to handle single quotes in strings. Is there an easier way?

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You can replace it with something else or remove it altogether. Not sure what other options there could be.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You can have strings with single quote if you double the single quote.
    That is O'Hara becomes O''Hara (2 single quotes). The concept is escaping a ' character.

  6. #6
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    What's meant by escaping quotes? does that mean "'"​? Is that another option? What's the accepted way of doing this?

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Did you read the problem and solution at the link provided?

    I have had applications where quotes and accented characters were included in the data.
    For storage purposes we stored the data in 2 forms ---1) no quotes, no accented characters
    and 2) as written.

    When processing -- searches were done against the non accented version.
    If changes were required/edits etc, use the Replace(accentedField,"'","''").

  8. #8
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Orange, Sorry I missed the link until you pointed it out. Very helpful, thanks.
    Does the solution they suggest of adding an extra quote only apply to data you're displaying in forms, and not to SQL? 'cause you say you don't use it for searches and keeping 2 tables in sync seems like a project on its own.

    Thanks for your help
    David

  9. #9
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    My suggestion was 2 fields in the same table record.

    tblA
    fld1 value without quote
    fld2 value with quote or accented char

    Use fld1 for searching (at least that' what we did)

    If you have to process the value in fld2 then use

    ValueToUse = Replace(fld2,"'","''")

  10. #10
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    ok need to play with this myself - using your example can I display fld2 in a textbox, edit it, move/remove the quote and save it back to the table?

    Thanks for you help

  11. #11
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,792
    Not wanting to seem too ignorant of the problem here, but this is only a problem with vba constructed sql, no? I know you can search, delete and append (so I guess update too) data with forms tied to queries or tables with no problem when it's "joey's" instead of "joeys". Not saying things like apostrophes or commas are good things to have in data, and I guess it might be queries and forms today but vba sql tomorow - just wondering if there really isn't an issue at present. I guess I've always had the luxury of clean data...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Quotes and apostrophes become an issue when constructing SQL strings in VBA. I deal with the apostrophe using Replace() function but the quote frustrates me so I forbid the use in data - so inch is not represented with ".

    I don't have a problem using Access Find/Replace for those characters. Wildcard characters are another issue. Have to escape by surrounding with [].
    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.

  13. #13
    Join Date
    Apr 2017
    Posts
    1,679
    Are those apostrophes (and possibly other characters) needed only for printout/display, or for some data exchange too?. When only for printout/display, then you can consider to use some Unicode character which looks like apostrophe (I'm sure there will be a lot of them), but is out of classic ASCII area.

  14. #14
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Hi Arvi,
    This sounds an interesting idea, can I have just one character in unicode, and the rest in ASCII. Does Unicode play well with SQL?

    Thanks
    David

  15. #15
    Join Date
    Apr 2017
    Posts
    1,679
    I have used Unicode in Excel, and have no direct experience in Access with it, but Access has CHRW() and ASCW() functions to operate with them, so I think to some extent you can use them - the best will be to check it out.

    I think you can insert an Unicode character without problems. When you don't want create your texts entries using formulas only, create a table where you store needed Unicode characters into text field. Then you can use simply copy and paste whenever you need to enter such character into your text.

    With queries you have to check it. I think query can return Unicode character without problems, but I'm not sure what happens when you include them in query string (p.e. as element of WHERE clause or JOIN condition).

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

Similar Threads

  1. Whether to Include a Calculated Field in a Table
    By Larry in TN in forum Access
    Replies: 9
    Last Post: 12-25-2015, 08:10 PM
  2. Replies: 5
    Last Post: 08-06-2013, 07:19 AM
  3. Replies: 10
    Last Post: 11-29-2012, 02:37 PM
  4. Replies: 2
    Last Post: 10-11-2012, 10:50 PM
  5. Replies: 3
    Last Post: 08-04-2011, 05:39 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
  •  
Other Forums: Microsoft Office Forums