Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Posts
    40

    Unanswered: Automatically "escape" characters?

    Hi, this is probably a bit of a n00b question, but if there are single quotes in SQL queries, how do you stop Jet from misinterpreting them as part of the statement syntax? In PHP/MySQL I would use a backslash before the quote - is it the same with VBA/Jet? So for example, I would want to make the correct version of this statement:

    Code:
    INSERT INTO Names (Surname) VALUES ('O'Neill');
    Also, often these names are coming from another file or user input, so is there an "automatically escape bad characters" function, so I could do

    Code:
    "INSERT INTO Names (Surname) VALUES ('" & auto_escape(txtSurname) & "');"
    sort of thing?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    They are escaped with themselves. Er... I mean:

    Code:
    "INSERT INTO NameT (name) VALUES ('O''Neil')"
    Note it is the same in T-SQL too (for apostrpohe - no need for double quotes).

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    ... so auto_escape would do something like

    Code:
    REPLACE(MyValue, "'", "''")
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Something that may be useful to you in the future
    Code:
    MsgBox "O" & Chr(39) & "Neill"
    George
    Home | Blog

Posting Permissions

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