Run-Time Error '-2147217900 (80040e14)': Incorrect Syntax near 's'.

EpicDave

New Member
Joined
Apr 14, 2016
Messages
4
I am trying to insert data into a SQL table from an excel table. I am able to get this code to work about 6 or 7 times but it hits a point where it hits this run time error.

'Setup Command Update
Dim BTcmd As ADODB.Command
Set BTcmd = New ADODB.Command
Dim r As Range
BTcmd.ActiveConnection = connex
For Each r In Range("A2", Range("A2").End(xlDown))
BTcmd.CommandText = Getinserttext(r.Value, r.Offset(0, 1).Value, r.Offset(0, 2).Value, r.Offset(0, 3).Value, r.Offset(0, 4).Value, _
r.Offset(0, 5).Value, r.Offset(0, 6).Value, r.Offset(0, 7).Value, r.Offset(0, 8).Value, r.Offset(0, 9).Value, r.Offset(0, 10).Value, _
r.Offset(0, 11).Value, r.Offset(0, 12).Value, r.Offset(0, 13).Value, r.Offset(0, 14).Value, r.Offset(0, 15).Value, r.Offset(0, 16).Value, _
r.Offset(0, 17).Value, r.Offset(0, 18).Value, r.Offset(0, 19).Value)
BTcmd.Execute
Next r


End Sub

Function Getinserttext(Invoice As String, Invoicestatus As String, DateRan As Date, Branchname As String, PayorName As String, LastID As String, EndDOS As Date, DSO As Integer, Type1 As String, Gross As Integer, Net As Integer, CA As Integer, Payments As Integer, AR As Integer, Difference As Integer, Percentage As Integer, Secondary As String, Lastworkeddate As String, Daysworked As Integer, OpenDt As Date) As String
Dim SqlStr As String
SqlStr = _
"INSERT INTO dbo.Dashboard (" & _
"Invoice,InvoiceStatus,<wbr>DateRan,BranchName,PayorName,<wbr>LastID,EndDOS,DSO,Type1,Gross,<wbr>Net,CA,Payments,AR,Difference,<wbr>Percentage,Secondary,<wbr>LastWorkedDate,DaysWorked,<wbr>OpenDt)" & _
"Values (" & _
"'" & Invoice & "'," & _
"'" & Invoicestatus & "'," & _
"'" & DateRan & "'," & _
"'" & Branchname & "'," & _
"'" & PayorName & "'," & _
"'" & LastID & "'," & _
"'" & EndDOS & "'," & _
"'" & DSO & "'," & _
"'" & Type1 & "'," & _
"'" & Gross & "'," & _
"'" & Net & "'," & _
"'" & CA & "'," & _
"'" & Payments & "'," & _
"'" & AR & "'," & _
"'" & Difference & "'," & _
"'" & Percentage & "'," & _
"'" & Secondary & "'," & _
"'" & Lastworkeddate & "'," & _
"'" & Daysworked & "'," & _
"'" & OpenDt & "')"

Getinserttext = SqlStr
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Here:-
Code:
DaysWorked,<wbr>OpenDt[B][COLOR=#FF0000])[/COLOR][/B]" & _
    "Values (" & _

I suspect you're missing a space after that closing parenthesis, otherwise SqlStr contains "OpenDT)Values".

Put a Debug.Print SqlStr statement after you've built the SQL and check what it looks like.
 
Upvote 0
That didn't seem to do anything. I am able to run through it with F8 for a few times and then it hits this error when I try to execute. My first guess is how I was defining the variable because the debug print is giving me an overflow error message when I remove the error execute and change the debug.
 
Upvote 0

Forum statistics

Threads
1,223,718
Messages
6,174,077
Members
452,542
Latest member
Bricklin

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