Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Criteria with quotation mark (2003)

    This is a classic one. I need to built a criteria string from data whit a quote inside( like Marcel's computer), of course is I built the criteria by using the "standard" way, I get an error for the data with a quote. For instance:
    MyString="Marcel's computer"
    strCriteria="[Computer]=" & MyString
    doesn't work.
    I know that one way is to double the quote to be able to use it in the criteria. So I am looking for this piece of code to solve this issue.
    Thanks and regards,
    Marcel

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Criteria with quotation mark (2003)

    In general, if you want to use a string value in a criteria string or in an SQL string, the value must be enclosed in quotes. You can use Chr(34) for this:

    strCriteria = "[Computer]=" & Chr(34) & MyString & Chr(34)

    The Chr(34) is a double quote, so you won't run into problems with strings containing a single quote, such as "Marcel's computer".

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Criteria with quotation mark (2003)

    Once again, thank you very much. Incredible how fast you are.
    Best regards,
    Marcel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •