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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in SQL-statement (Insert)

Status
Not open for further replies.

JB83

Programmer
Oct 3, 2002
44
NL
Dear reader(s),

I have a problem with DoCmd.RunSQL: when I want to add a record in a table with a WHERE-clause I get a syntax error, and I don't know how to solve the problem.


DoCmd.RunSQL ("INSERT INTO [tblReasons] (Reason1, Reason2, Reason3, Reason4, Reason5, Reason6)
SELECT " & defReason & " , " & defReason & " , " & defReason & ", " & defReason & " , " & defReason & " , " & defReason & " WHERE docNumber = txtDocNumber.Value")


Thanks in advance,

Jochen. --------------------------------------------------------------------------------
It never hurts to help and it never helps to hurt.
 
In the Reason variables are text, you need single quotes. Also if txtDocNumber is a form field, it also need quotes:

DoCmd.RunSQL ("INSERT INTO [tblReasons] (Reason1, Reason2, Reason3, Reason4, Reason5, Reason6)
SELECT '" & defReason & "' , '" & defReason & "' , '" & defReason & "', '" & defReason & "' , '" & defReason & "' , '" & defReason & "' WHERE docNumber = '" & txtDocNumber.Value & "'")

Code away!
Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Thank you for your reply. I already have found a solution myself.

Keep up the good work!

[2thumbsup] --------------------------------------------------------------------------------
It never hurts to help and it never helps to hurt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top