By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,473 Members | 3,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,473 IT Pros & Developers. It's quick & easy.

SQL INSERT INTO PROBLEM

P: n/a
I have the following lines in a macro:
sql = "INSERT INTO IM (ITEM, DESC) VALUES (vitem, ndesc)"

DoCmd.RunSQL sql

Every time I execute the macro, I get a run time error saying there is a
syntax error in the INSERT INTO command. I have tried numerous variations
with the same result.

I would greatly appreciate anybody's help in pointing me in the right
direction.

John Cantlin
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Assuming vitem and ndesc are variables, they need to be outside of the
string so that you get their value in the SQL statement, not just their
name. For text fields, you need to enclose the value in quotes.

Assuming Item is a numeric field and Desc a text field, something like:

sql = "INSERT INTO IM (ITEM, [DESC]) VALUES (" & vitem & ", '" & ndesc &
"')"

BTW, I'd rename the second field. I believe that DESC is a reserved word,
and shouldn't be used for anything.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

<jp*******@cox.net> wrote in message
news:cQnxd.60657$ka2.26515@fed1read04...
I have the following lines in a macro:
sql = "INSERT INTO IM (ITEM, DESC) VALUES (vitem, ndesc)"

DoCmd.RunSQL sql

Every time I execute the macro, I get a run time error saying there is a
syntax error in the INSERT INTO command. I have tried numerous variations
with the same result.

I would greatly appreciate anybody's help in pointing me in the right
direction.

John Cantlin

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.