Solved

MS Access 2010 VBA Execute SQL Too Few Parameters

Posted on 2014-09-12
4
372 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

739 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