Results 1 to 6 of 6
  1. #1
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114

    Use Single Quote in Access VBA DoCmd Statement

    Greetings - I am wanting to use the replace function in access vba to replace all single quotes with null. I have this syntax, but compile error.



    Code:
    DoCmd.RunSQL "update [Vendorlist] 
    set [jobdesc] = replace([jobdesc], "'", "")
    where [jobdesc] like "*'*";"

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    put it in a query.
    the query works.

    UPDATE Vendorlist SET [jobdesc] = Replace([jobdesc],"'","") WHERE (((tClients.[jobdesc]) Like "*'*"));

  3. #3
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114
    Quote Originally Posted by ranman256 View Post
    put it in a query.
    the query works.

    UPDATE Vendorlist SET [jobdesc] = Replace([jobdesc],"'","") WHERE (((tClients.[jobdesc]) Like "*'*"));
    Requirements need it to be VBA

  4. #4
    Join Date
    Apr 2017
    Posts
    1,792
    Do you want elliminate all single quotes from field [jobdesc], i.e. replace all single quotes with nothing?

    Or do you want to replace all entries in field [jobdesc] equal to "'" with NULL value?

  5. #5
    chalupabatman is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2016
    Posts
    114
    Quote Originally Posted by ArviLaanemets View Post
    Do you want elliminate all single quotes from field [jobdesc], i.e. replace all single quotes with nothing?

    Or do you want to replace all entries in field [jobdesc] equal to "'" with NULL value?
    Replace all single quotes from the field [jobdesc] with nothing.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Compile error because you are not using concatenation and line continuation. Also, the embedded quote marks are an issue. Don't really need the filter criteria.

    If you don't want warning popups, one approach is:

    CurrentDb.Execute "update [Vendorlist] set [jobdesc] = replace([jobdesc], Chr(39), '')"

    But since Chr() is calling a VBA function:

    CurrentDb.Execute "update [Vendorlist] set [jobdesc] = replace([jobdesc], ""'"", '')"

    Note use of doubled quote marks to 'escape' the character so the query will recognize as a literal character, not a special character.

    Note use of two apostrophes for the embedded empty string, otherwise use four quotes.
    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: 05-23-2017, 12:55 PM
  2. Replies: 2
    Last Post: 09-27-2016, 09:10 PM
  3. Single Quote in Cascading Combo Box
    By crockee in forum Programming
    Replies: 3
    Last Post: 05-28-2016, 07:23 AM
  4. Replies: 1
    Last Post: 02-09-2016, 07:03 AM
  5. problem with my DoCmd.RunSQL statement
    By cgclower in forum Access
    Replies: 1
    Last Post: 07-24-2011, 06:12 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