Results 1 to 9 of 9
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Append employee name with '


    I have an employee name with a ' in it (i.e. O'Neal). I know I have done this before but it has been a while and I cannot remember how to do it for the life of me. I'm executing the query in VBA using the mySQL as a string method. Can someone help me out with the syntax on this? OR if you have a webpage that explains this I would greatly appreciate that as well. Thanks in advance.

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Tried this....didn't work.

    Code:
    Dim mySQL, strQuote as String
    strQuote = """"
    
    mySQL = "...'" & strQuote & vFULL_NAME & strQuote & "'...;"

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    "update allfieldtype set ftext='O''Neal'" (two ' between O and Neal)

    or
    abc="O''Neal" (two ' between O and Neal)

    currentdb.Execute "update allfieldtype set ftext='" &abc & "'"

  4. #4
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Now I really have the solution....

    Replace the ' with '' (two single quotes, NOT a double quote)
    Code:
    variableName = Replace(String, "'", "''")

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Didn't see your post before mine weekend00. Thanks for the input!

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Glad to see you work it out.

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Can you explain how the replace function works? I'm replacing O'Neal with O''Neal so the variable value is in fact O''Neal. However, when I run the SQL and append the record into the table it appends as O'Neal. Why?

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    the replace function works as you expected, it replace O'Neal to O''Neal,
    when the SQL runs, it look on '' as ',("" will be look on as " too) while a single ' (or ") is part of the syntax, not a part of the fields's content. That's why it will cause SYNTAX ERROR when you use single ' in you text.

    to understand better, please think about these:

    statements:
    abc="O''Neal"
    currentdb.Execute "update allfieldtype set ftext='" &abc & "'"

    after the statements run, ftext is set to O'Neal,

    T-chart for abc and ftext:
    Code:
    abc                 ftext
    abc="O''Neal"     O'Neal
    abc="O""Neal"     O"Neal
    abc="O""''Neal"     O"'Neal
    abc=""""""             ""
    abc="''''"              ''

  9. #9
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok, makes more sense. Thank you.

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

Similar Threads

  1. Employee Tracking
    By nycon in forum Access
    Replies: 6
    Last Post: 10-27-2010, 05:42 PM
  2. Quit/Terminated Employee Table
    By mwabbe in forum Access
    Replies: 6
    Last Post: 09-24-2010, 02:37 PM
  3. Employee Attendance database
    By oxicottin in forum Database Design
    Replies: 0
    Last Post: 02-14-2007, 02:58 PM
  4. Qry that asks for specific employee name
    By oxicottin in forum Queries
    Replies: 0
    Last Post: 02-05-2007, 08:50 PM
  5. Replies: 5
    Last Post: 05-02-2006, 11:25 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