Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Kay is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    10

    Replace double quotes

    Hello,

    I am trying Replace Double Quote in code ( ") with wild card . It throws Runtime error '3075' -- Missing operator in query expression.

    Dim strComment As String
    Dim stra As String
    Dim strb As String
    Dim strAE As String
    Dim strBE As String
    stra = "'"
    strb = """"
    str1AE = "`"
    str2BE = "`"



    strComment = [Forms]![Test Form1A]![Comment] & ""
    strComment = Replace(strComment, a, strAE)
    strComment = Replace(strComment, strb, strBE)


    Plz advise.

    Thanks

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Not exactly sure what your trying to accomplish but lets look at your code line by line

    The 4 Dim functions look fine
    Dim strComment As String
    Dim stra As String
    Dim strb As String
    Dim strAE As String
    Dim strBE As String

    stra = "'"
    stra now has the value '
    strb = """"
    strb now has the value "
    str1AE = "`"
    str1AE now has the vale `
    str2BE = "`"
    str2BE now has the value ` which is exactly the same as str1AE get rid of this statement it's pointless

    Ok now lets look at each statement below

    strComment = [Forms]![Test Form1A]![Comment] & ""
    the & "" is totally useless it doesn't do anything at all Revise this to
    StrComment = [Forms]![Test Form1A]![Comment]
    the results will be exactly the same


    strComment = Replace(strComment, a, strAE)
    I'm going to presume you mean stra not a If this is your actual code and you have option explicit the variable doesn't exist.
    This statement takes the value in strcomment and replaces all ' values with ` values


    strComment = Replace(strComment, strb, strBE)
    This statement takes all " and replaces them with ` change the strBE to strAE you get the same result

    Now as to your error message. without knowing the context of this code I can't answer that. Is the code a function or a procedure or one of the events of a control on a report or form? Your setting the value of a variable within the code but that doesn't go anywhere so it's a waste. You really need to give us a better idea of what your trying to do to get better help

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, I noticed:

    str1AE is not defined
    str2BE is not defined
    a is not defined


    Do you have These two lines at the top of every code page?
    Code:
    Option Compare Database
    Option Explicit

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, variables declared are not the variables used.

    I don't see a wildcard character in that code. What is ` character? Appears to be Chr(96) whereas apostrophe is Chr(39). I have known this character to cause issue when accidentally used (by copy/paste of code sample) instead of regular apostrophe.
    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.

  5. #5
    Kay is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    10
    Thank you for your quick responses.

    Yes you are right a is actually stra and b is strab.

    By replacing stra with StrAE I was able to convert the value with single quote such as Kay' to Kay`.

    The user input this value in the Test Form which will be stored in SQL Table.

    I was not able to do so for Double Quote value such as Kay" to Kay`.

    The real issue is I was n't able to store data in the backend which is MS SQL.

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

    strComment = Replace(strComment, Chr(34), strAE)
    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.

  7. #7
    Kay is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    10
    Nope.. It throws same error again as below.


    Click image for larger version. 

Name:	Error.png 
Views:	26 
Size:	20.9 KB 
ID:	10265

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I don't use SQL BE, just Access.

    When I want to allow a literal apostrophe in a value of an SQL statement I use:

    Replace(strSampledFrom, "'", "''")

    Never tried to Replace quote mark.

    I don't know what that other character is that you are trying to use. Just did this quick test in VBA immediate window and it worked:

    ?Replace("KJ""KJ",Chr(34),Chr(96))

    However, this fails:
    ?Replace("KJ"KJ",Chr(34),Chr(96))

    Which is why I instruct my users not to put " in any data - verboten!
    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.

  9. #9
    Kay is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    10
    Thanks for trying to help me ..

    When i am trying to debug the issue this is where it fails :db.Execute strsql, dbFailOnError

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yes, the SQL is choking on the extra quote mark. I edited my previous post, perhaps after you first read it.
    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.

  11. #11
    Kay is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    10
    Thanks June7! still haven't figured out how I can convert it.

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Aha!
    For single quotes (ex: O'Brian) I use this function to double up on the single quote:
    Code:
    Function ConvertQuotesSingle(InputVal)
       ConvertQuotesSingle = Replace(InputVal, "'", "''")
    End Function
    Expanded, it looks like this:
    = Replace(InputVal, " ' ", " ' ' ")


    In the SQL, useage is:

    Code:
    <snip>
    ...... & ConvertQuotesSingle(ubLast) & "', '" & ConvertQuotesSingle(ubFirst) & "', '"
    <snip>

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I have tried and gave up and that's why I forbid use of " mark in data. My users will catch hell from me if my SQL fails because they disobeyed. I don't like apostrophes either but can deal with them.
    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.

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Agreed! I use the replace function and remove the (") mark before the data is saved. But have to deal with apostrophes in names and addresses.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    How do you make the Replace function work for quote mark? As I show in earlier post I can't get that to work. This is also the OP's issue.
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Getting the Quotes right
    By aytee111 in forum Programming
    Replies: 2
    Last Post: 10-11-2012, 08:04 PM
  2. New Database on Customer Quotes
    By rkalapura in forum Access
    Replies: 2
    Last Post: 07-13-2012, 07:15 PM
  3. Replies: 3
    Last Post: 06-07-2012, 07:05 AM
  4. Database to produce quotes
    By rossp0203 in forum Database Design
    Replies: 2
    Last Post: 05-26-2011, 10:15 AM
  5. Remove Quotes within Data Values
    By kfschaefer in forum Programming
    Replies: 0
    Last Post: 02-26-2009, 01:15 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