Run-time error '-2147217900 (80040e14)': Syntax error or access violation

kristianb63

New Member
Joined
Oct 3, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello

I have a macro that I'm using to call a SQL stored procedure that contains variables that are passed from Excel. I have removed the values that identify the server / db name and sp name

When executing the sp from with in SQL the report works. When i try in Excel, using the same values for the parameters, it returns the Run-time error '-2147217900 (80040e14)': Syntax error or access violation

The debug yellows on the Set rs = cmd.Execute() line of the macro

Could anybody help please?









Sub CIS_REFRESH()


Application.ScreenUpdating = False

Sheet3.Range("A2:Z1000000").ClearContents

''2- Declare Variables

Dim osheet As String
Dim orange As String
osheet = "CIS_REPORT"
orange = "A2"

Dim bu_name As String
Dim INVOICEFROM As String
Dim INVOICETO As String


Dim Conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset

bu_name = UCase(Sheet13.Cells(6, 3))
INVOICEFROM = (Sheet13.Cells(7, 4))
INVOICETO = (Sheet13.Cells(8, 4))


'Function ConnectSQLServerStoredProc(osheet As String, orange As String, Server As String, Jurisdiction As String)

'SQL Connection
Set Conn = New ADODB.Connection
Set rs = New ADODB.Recordset

Conn.ConnectionString = "Provider=SQLOLEDB;;Server=REMOVED;Database=REMOVED;Trusted_connection=yes;"
Conn.Open
Set cmd = New ADODB.Command


cmd.ActiveConnection = Conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "REMOVED FOR CONFIDENTIALITY"
cmd.Parameters.Append cmd.CreateParameter("@bu_name", adVarChar, adParamInput, 60, bu_name)
cmd.Parameters.Append cmd.CreateParameter("@INVOICEFROM", adVarChar, adParamInput, 60, INVOICEFROM)
cmd.Parameters.Append cmd.CreateParameter("@INVOICETO", adVarChar, adParamInput, 60, INVOICETO)


Set rs = cmd.Execute()

If Not rs.EOF Then
Sheets(osheet).Range(orange).CopyFromRecordset rs
rs.Close
Else: MsgBox "No Records", vbCritical
End If

If CBool(Conn.State And asStateOpen) Then Conn.Close
Set Conn = Nothing
Set rs = Nothing
Set cmd = Nothing




End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,738
Messages
6,174,207
Members
452,551
Latest member
croud

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