Run-Time Error 3134 - Syntax Error in Insert Into Statement

davidb88

Board Regular
Joined
Sep 23, 2013
Messages
76
Hi -

I have an Insert Into Statement in my VBA code and I keep getting a run-time error 3134. I know there are a number of posts about this type of problem and I have tried all of the solutions I have found but nothing seems to work for this particular string. If someone sees the issue, can you please point it out? Thanks.

Code:
strSQL = "INSERT INTO tblPDcalc ([Month End], [Loan Type], [FICO Band], [r1PD], [r2PD], [r3PD], [r4PD], [r5PD], " _
        & "SELECT (#" & modeldate & "#, '1st Mtg', '1', " _
        & " " & r1PD & ", " & r2PD & ", " & r3PD & ", " & r4PD & ", " & r5PD & ");"


DoCmd.RunSQL (strSQL)
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
double speech marks on beginning of line three look suspicious to me
 
Upvote 0
Why are you using SELECT when the values you are inserting aren't coming from a table/query.

This is the syntax for inserting values:

INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
 
Upvote 0
You are missing a closing parentheses (and have an extra comma too, I think).

Are the value you are "selecting" supposed to come from a table, or are they literal values. It looks like literal values. The correct sql should be something like:

Code:
[COLOR="#000080"]INSERT INTO[/COLOR] TblPDCalc ( [I]Field1[/I], [I]Field2[/I], [I]Field3[/I], .... )
[COLOR="#000080"]VALUES [/COLOR]( [I]Value1[/I], [I]Value2[/I], [I]Value3[/I], ... )
 
Upvote 0
Thanks for the responses. I was able to get the code to work now! Here is the final code in case anyone else needs something similar:
Code:
'Append PD calculations to tblPDcalc
strSQL = "INSERT INTO tblPDcalc ([Month End], [Loan Type], [FICO Band], [r1PD], [r2PD], [r3PD], [r4PD], [r5PD]) " _
        & "VALUES (#" & modeldate & "#, '1st Mtg', '1', " & r1PD & ", " & r2PD & ", " & r3PD & ", " & r4PD & ", " & r5PD & ");"


DoCmd.RunSQL (strSQL)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,513
Messages
6,114,064
Members
448,545
Latest member
kj9

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top