Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with SQL insert statement and apostrophe 1

Status
Not open for further replies.

needadvice

Programmer
Apr 7, 2002
145
US
I have a data entry form with a field named [Statement].
The entry in this field is then inserted in a table via an sql insert statement. If the [statement] field contains an apostrophe it woun't insert.
I know it has something to do with strQuote = Chr$(34) but I don't know exactly how to fix this.
Any help greatly appreciated.
 
It would help if you post your code. But you may just need to put quotes around you apostrophe. It is probably reading the ' as the beginning of a value eg.

where date = '01/

Dodge20
 
This sounds like you have something like

Code:
"INSERT INTO tblName ( field1, field2, .. .. etc )
  VALUES ('" & [Statement] & "', value2 .. .. etc )"


When JET parses this the first single quote is seen as the start of the text and the apostrophe as the end of the text.
Whatever comes after the apostrophe is seen as a problem.

You need to replace the single quotes either side of the text with double double quotes. Ie.
Code:
""

So the example above becomes
Code:
"INSERT INTO tblName ( field1, field2, .. .. etc )
  VALUES (""" & [Statement] & """, value2 .. .. etc )"



'ope-that-'elps.




G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Here is my insert statement. I'm not sure I understand where I would put the quotes. I tried in the data entry field but that didn't work.

DoCmd.RunSQL ("insert into 189TBL([DateofClaim],[CWEdate],[BenifitsPaid],[SSN],[wageearning],[Garnishment],[Tax],[RefundType],[Statement],[FName],[LName],[CITY],[STATE],[ZIP],[STREET],[DateofMailing],[AMOUNTOVERPAID],[LocalOffice],[ProgramCode],[OLDWBR],[NEWWBR],[PBENEFITS],[ORIGBENEFITSPAID])Values(#" & DCLAIM & "#, #" & CWEDATE & "#," & BENPAID & ",'" & SSN & "'," & WAGE & "," & GARNISHMENT & "," & TAX & ",'" & REFUNDTYPE & "','" & STATEMENT & "','" & FNAME & "','" & LNAME & "','" & CITY & "','" & STATE & "','" & ZIP & "','" & STREET & "', #" & DATEOFMAILING & "#,'" & LOCALOFFICE & "','" & OLDWBR & "','" & NEWWBR & "','" & AMOUNTOVERPAID & "','" & PROGRAMCODE & "','" & PBENEFITS & "','" & BENPAID & "')")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top