Apostrophe & other special char

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

SQL = "INSERT INTO TABLEA VALUES('" & Forms![Form1]!job & "','" &
Forms![Form1]!description & "')"
DoCmd.RunSQL SQL

From tha line of codes, it would have runtime error when
Forms![Form1]!description contains an apostrophe. What's the workaround ?

Thanks in advance.
 
SQL = "INSERT INTO TABLEA VALUES('" & Forms![Form1]!job & "','" &
Replace(Forms![Form1]!description, "'", "''") & "')"

To make it easier to read, that's

Replace(Forms![Form1]!description, " ' ", " ' ' ")
 
Douglas, you're the man. Before I've read your resolution I used " as
delimiter but then it would be a problem if a " is entered. Your solution is
covers all. Thanks.

Douglas J. Steele said:
SQL = "INSERT INTO TABLEA VALUES('" & Forms![Form1]!job & "','" &
Replace(Forms![Form1]!description, "'", "''") & "')"

To make it easier to read, that's

Replace(Forms![Form1]!description, " ' ", " ' ' ")


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JJ said:
SQL = "INSERT INTO TABLEA VALUES('" & Forms![Form1]!job & "','" &
Forms![Form1]!description & "')"
DoCmd.RunSQL SQL

From tha line of codes, it would have runtime error when
Forms![Form1]!description contains an apostrophe. What's the workaround ?

Thanks in advance.
 
Back
Top