2

I'm getting the error "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another" while trying to call a SQL Server stored procedure from Excel/VBA.

Can't figure out how to call from VBA?

Stored Procedure Parameters

CREATE PROCEDURE [dbo].[sp_Productivity_GetIndividuals] (
@startDate DATE,
@endDate DATE)
....



VBA Code

Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command

With cmd
    .ActiveConnection = con
    .CommandText = "sp_Productivity_GetIndividuals"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("@startDate", adDate, adParamInput, , "3/1/2014")
     .Parameters.Append .CreateParameter("@endDate", adDate, adParamInput, , "3/31/2014")
    Set rs.ActiveConnection = .Execute
End With
0

1 Answer 1

1

Try passing your dates as "2014-03-01" and it will work. If you start with an excel date parameter, use FORMAT to convert to string, as in:

.Parameters.Append .CreateParameter("@startDate", adDate, adParamInput, , Format(now(),"yyyy-mm-dd"))
Sign up to request clarification or add additional context in comments.

3 Comments

I changed the code to the below, but I still get the exact same error.
Sorry for last post (I'm a rookie on formatting). I changed the code to the suggestion but I get the exact error.
What if you try .Parameters.Append .CreateParameter("@startDate", adDate, adParamInput, , "2014-03-31")?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.