SQL Error Help

R

RayToddJr

I have the following SQL:

strSQL = "INSERT INTO taDEFENDANTS(TrusteeDefendantID)" & _
"VALUES(lngTrusteeDefendantID)" & _
"WHERE DefendantID=" & lngDefendantID & ";"

The Problem:

I get the following error:

Run-time error 3137:
Missing semicolon (;) at end of SQL statement

What am I missing that prevents the code from seeing the semicolon that is
there?

Sorry if this is double posted. My system crashed right after I clicked
post and never saw the first posted.
 
J

John Spencer

What you are missing is that an INSERT statement adds records. Therefore
there is no WHERE clause that applies with this syntax.

Also you need the value of lngTrusteeDefendantID inserted into the SQL string
and not a reference to the variable - which won't be recognized

Plus you were missing spaces whenever you had a new line.

strSQL = "INSERT INTO taDEFENDANTS(TrusteeDefendantID)" & _
" VALUES(" & lngTrusteeDefendantID & ")"

OR perhaps you want an UPDATE query and not an insert query?
strSQL = "Update taDEFENDANTS(TrusteeDefendantID)" & _
" Set TrusteeDefendantID =" & lngTrusteeDefendantID & " & _
" WHERE DefendantID=" & lngDefendantID

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
R

RayToddJr

Thanks John.

Ray.

John Spencer said:
What you are missing is that an INSERT statement adds records. Therefore
there is no WHERE clause that applies with this syntax.

Also you need the value of lngTrusteeDefendantID inserted into the SQL string
and not a reference to the variable - which won't be recognized

Plus you were missing spaces whenever you had a new line.

strSQL = "INSERT INTO taDEFENDANTS(TrusteeDefendantID)" & _
" VALUES(" & lngTrusteeDefendantID & ")"

OR perhaps you want an UPDATE query and not an insert query?
strSQL = "Update taDEFENDANTS(TrusteeDefendantID)" & _
" Set TrusteeDefendantID =" & lngTrusteeDefendantID & " & _
" WHERE DefendantID=" & lngDefendantID

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top