Results 1 to 2 of 2
  1. #1
    NISMOJim is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    273

    Apostrophe in name

    Here's an interesting problem I just ran into for the first time. I have the following query code on my form (frmXacn) to pull up training information when an employees name is entered...

    Set rsTrng = db.OpenRecordset("SELECT EName, Course, Passed FROM qryTraining WHERE ([EName] = '" & Forms!frmXacn!txtXacnEmpName & "');")

    One of the employees has an apostrophe in his last name (D'Ano, Mike), so I get the following error when his name is put through the query...

    Run-time error '3075':
    Syntax error (missing operator) in query expression
    'On TrackName = 'D'Ano, Mike".



    I understand why the code thinks there is an error, but is there a way to get around it for a case like this?

    Thanks again for your help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try:

    WHERE (Replace([EName], "'", "''") = '" & Replace(Forms!frmXacn!txtXacnEmpName, "'", "''") &

    Really should use EmployeeID for criteria instead of names.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-26-2012, 09:47 AM
  2. Replies: 4
    Last Post: 10-15-2012, 11:38 AM
  3. Replies: 5
    Last Post: 09-05-2012, 09:28 AM
  4. Replies: 2
    Last Post: 02-16-2012, 04:29 PM
  5. Replies: 6
    Last Post: 11-19-2011, 09:47 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