0

Thank you in advance. I am trying to run a stored procedure from excel which accepts input parameters and it is giving error Run-time error '-2147217900 (80040e14)' automation error.

   Set cmd1 = New ADODB.Command
             With cmd1
             .ActiveConnection = sConnString
             .CommandText = "spGetPriceChangeTest"
             .CommandType = adCmdStoredProc
             .CommandTimeout = 360
             .Parameters.Append .CreateParameter("@suppliercode", adVariant, adParamInput, , Range("A" & (x + 2)).Value)
             .Parameters.Append .CreateParameter("@date1", adDBTimeStamp, adParamInput, , datetime)
             .Parameters.Append .CreateParameter("@proddescription", adVariant, adParamInput, , Range("D" & (x + 1)).Value)
             .Parameters.Append .CreateParameter("@vendorcode", adVariant, adParamInput, , Range("C" & (x + 2)).Value)
             .Parameters.Append .CreateParameter("@type", adVariant, adParamInput, , Range("B" & (x + 2)).Value)
             End With
             Set rst1 = New ADODB.Recordset
             Set rst1 = cmd1.Execute
19
  • You're Set-ing the exact same object reference twice: Set rst1 = New ADODB.Recordset is redundant and can be removed. Commented Feb 6, 2018 at 21:10
  • Is there not an actual opened connection somewhere? Which specific line is throwing the error? Commented Feb 6, 2018 at 21:14
  • removed it. Same error. Commented Feb 6, 2018 at 21:15
  • I know, I was just saying it's redundant. Do you have an ADODB.Connection object that you .Open anywhere? I've never used a ADODB.Recordset without an explicit ADODB.Connection... also try removing the @ from the parameter names, and make sure the parameters are supplied in the exact same order as the SP is expecting them. Commented Feb 6, 2018 at 21:17
  • 1
    You're going to have to try a bit harder than that... SO is Q&A, not "hold my hand until it works" ;-) Commented Feb 6, 2018 at 21:47

2 Answers 2

1

When creating a parameter, ensure that the size defined in SQL is mentioned in the .CreateParameter("",adVarchar,10,value)

This post helped. It talks about how we can capture an error in detail.

https://support.microsoft.com/en-us/help/167957/info-extracting-error-information-from-ado-in-vb

Sign up to request clarification or add additional context in comments.

Comments

0

Try using EXEC:

.CommandText = "exec spGetPriceChangeTest"

2 Comments

Given .CommandType = adCmdStoredProc, I doubt this would be it. Changing .CommandType to adCmdText as well, could work though.
I have another stored procedures not accepting any parameters and it works as the code above perfectly. Im sensing that the datatype or the datetime parameter is an issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.