INSERT statement contains fewer items than the insert list

J

J. Muenchbourg

The block of code below shows how I am inserting field values into my
dbase table:

strSQLStatement = "INSERT INTO tblArticles
(handid,ArticleDate,sport,articleheader, fpick,articleText) "_
& "SELECT '" & handid & "' As handid, '" _
& ArticleDate & "' As ArticleDate, '" _
& sport & " As sport, " _
& articleheader & "' As articleheader, '" _
& fpick & "' As fpick, '" _
& articleText & "' As articleText;"

Conn.Execute(strSQLStatement)

...but I am getting an "Insert statement contains fewer items than the
insert list" error , when in fact I am not (both 6 field names).

????
Muench
 
T

Turkbear

The block of code below shows how I am inserting field values into my
dbase table:

strSQLStatement = "INSERT INTO tblArticles
(handid,ArticleDate,sport,articleheader, fpick,articleText) "_
& "SELECT '" & handid & "' As handid, '" _
& ArticleDate & "' As ArticleDate, '" _
& sport & " As sport, " _
& articleheader & "' As articleheader, '" _
& fpick & "' As fpick, '" _
& articleText & "' As articleText;"

Conn.Execute(strSQLStatement)

..but I am getting an "Insert statement contains fewer items than the
insert list" error , when in fact I am not (both 6 field names).

????
Muench

Try a
Response.Write (strSQLStatement)
to see if perhaps the quotes or commas are getting misplaced...
 
H

Harry Strybos

J. Muenchbourg said:
The block of code below shows how I am inserting field values into my
dbase table:

strSQLStatement = "INSERT INTO tblArticles
(handid,ArticleDate,sport,articleheader, fpick,articleText) "_
& "SELECT '" & handid & "' As handid, '" _
& ArticleDate & "' As ArticleDate, '" _
& sport & " As sport, " _
& articleheader & "' As articleheader, '" _
& fpick & "' As fpick, '" _
& articleText & "' As articleText;"

Conn.Execute(strSQLStatement)

..but I am getting an "Insert statement contains fewer items than the
insert list" error , when in fact I am not (both 6 field names).

????
Muench

Try this:

strSQLStatement = "INSERT INTO tblArticles
 
A

Aaron Bertrand - MVP

Uh, did you mean

strSQLStatement = "INSERT tblArticles (handid, ...) VALUES('" & handid & "',
....)"

(I've never seen As used for aliases in an *insert* statement; not saying
that it wouldn't work, but it looks weird, and bloats your code
unnecessarily.)

Also, a good debugging technique, as always, is

Response.Write (strSQLStatement)

In this case, you are very likely to spot the problem without having to post
a message at all. And when you do have to post a message, you give us more
useful information than an unpopulated SQL statement...
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top