Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access 2010 VBA Execute SQL Too Few Parameters

Posted on 2014-09-12
4
Medium Priority
?
380 Views
Last Modified: 2014-09-12
I am using vba in an attempt to append a row in a table.

'Build the -Insert SQL Statement
strInsertSQL = "INSERT INTO tblFeature(Cat_No, Fea_ID, Fea_Name,Fea_Descr,Fea_Syntax,Fea_URL) " & _
"VALUES(intCatNo, strFeaID, strFeaName,strFeaDescr,strFeaSyntax,strFeaURL)"
 
'Execute the sql statement
CurrentDb.Execute strInsertSQL

Worked when values were hard coded.

Watch window shows values for all variables.

What am I missing?

Thanks,
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Anthony Berenguel earned 1000 total points
ID: 40319683
try this
strInsertSQL = "INSERT INTO tblFeature(Cat_No, Fea_ID, Fea_Name,Fea_Descr,Fea_Syntax,Fea_URL) " & _
"VALUES(" & intCatNo & ", '" & strFeaID & "', '" & strFeaName & "', '" & strFeaDescr & "', '" & strFeaSyntax & "', '" & strFeaURL  & "')"

Open in new window

0
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 1000 total points
ID: 40319698
To add just a bit, you were passing the variable names as literal's in the statement, not the value those variables contain.

The way your statement was, the letters 'intCatNo' was actually being used for the value.   You can see that clearly by putting a STOP just above the execute, then looking at the SQL Statement.

Contrast that to what Anthony suggested and you'll see the difference.

Jim.
0
 

Author Comment

by:Dovberman
ID: 40319703
Yes, I noticed this when I hard coded the values.

Thanks,
0
 

Author Closing Comment

by:Dovberman
ID: 40319705
Thank you both.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question