Results 1 to 3 of 3
  1. #1
    jpeat is offline Novice
    Windows 2K Access 2007
    Join Date
    Jan 2012
    Posts
    5

    Linking a textbox to data that contains an apostrophe

    Hello,

    I'm having an issue with my database involving text that contains apostrophes. I have created a form with a series of textboxes. I have written code for each textbox telling it to source (and populate itself with) a particular paragraph from a table (when certain other criteria are met).

    Some of these paragraphs have words in them which contain apostrophes and this seems to be the issue. When I run the code below, the textbox (Text50) will populate with the correct paragraph of text (even if it includes apostrophes), but when I use this textbox as a reference for a different textbox (Text81), I receive the error "Syntax Error (missing operator) in query expression" - but only when the paragraph of text contains an apostrophe.

    [Forms]![User Interface 3]![Text50] = DLookup("[Competency Description]", "[Competency Query 2]", "[Competency Order] = '2.9'")

    [Forms]![User Interface 3]![Text81] = DLookup("[Competency Category]", "[Competency Query 2]", "[Competency Description] = '" & [Forms]![User Interface 3]![Text50] & "'")

    Any ideas would be very much appreciated!

    Many thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,962
    Try quotes in place of the apostrophes:
    "[Competency Description] = """ & [Forms]![User Interface 3]![Text50] & """")

    or Chr()
    "[Competency Description] = " & Chr(39) & [Forms]![User Interface 3]![Text50] & Chr(39))

    or double the apostrophes within the string

    "[Competency Description] = '" & Replace([Forms]![User Interface 3]![Text50],"'", "''") & "'")

    Review this http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    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.

  3. #3
    jpeat is offline Novice
    Windows 2K Access 2007
    Join Date
    Jan 2012
    Posts
    5
    Hi June7,

    Thank you so much, the second option worked perfectly (although I just had to change the 39 to 34)!!!

    Many thanks again

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

Similar Threads

  1. Replies: 4
    Last Post: 12-22-2011, 03:04 AM
  2. Replies: 6
    Last Post: 11-19-2011, 09:47 PM
  3. TextBox control not linking to query data
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 09-28-2011, 09:56 AM
  4. Replies: 4
    Last Post: 01-05-2011, 07:56 AM
  5. Basic help linking data to a report?
    By SportyDog in forum Reports
    Replies: 3
    Last Post: 11-30-2009, 02:26 AM

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