Solved

MS Access 2010 VBA Execute SQL Too Few Parameters

Posted on 2014-09-12
4
359 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
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Anthony Berenguel earned 250 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 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now