4

I have the following stored procedure in SQL server and can call it just fine from within SQL Server:

CREATE PROCEDURE uspRecipeNote
    @IngString varchar(255) OUTPUT,
    @MixID int = NULL
AS 
    SET NOCOUNT ON;
    SET @IngString = dbo.ufnRecipeNote(@MixID);

I have been using VBA in Access to call stored procedures for months and have never had a problem, but have tried several possibilities and am stumped, getting either of the following errors, depending upon what I have tried:

"Parameter object is improperly defined. Inconsistent or incomplete information was provided." "Procedure or function uspRecipeNote has too many arguments specified."

Here is what I have at this point in VBA:

Set cmd.ActiveConnection = cn
cmd.CommandTimeout = 0
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "uspRecipeNote"

'add parameters
cmd.Parameters.Append cmd.CreateParameter("@IngString", adVarChar, adParamOutput)
cmd.Parameters.Append cmd.CreateParameter("@MixID", adInteger, adParamInput, , intMixID)

cmd.Execute

I get an error on the first parameter no matter what I have tried. I suspect it is something simple. Thanks in advance for any help!

5
  • Have you tried putting the output parameter last instead of first in the SP? Commented Apr 1, 2016 at 16:45
  • Yes, that is my typical practice, but I switched them as one of my attempts to make it work. Commented Apr 1, 2016 at 16:51
  • When I type in what you have above, VBA automatically inserts a ";" as follows: Debug.Print cn.Execute; "uspRecipeNote " & intMixID Commented Apr 1, 2016 at 17:02
  • No problem. I have tried several options using parentheses, to no avail. When I try what you have listed above, I get "Procedure or function 'uspRecipeNote' expects parameter '@MixID', which was not supplied." Commented Apr 1, 2016 at 17:27
  • Also you can use Execute instead ADODB.Commands and put into record set Dim rs as New ADODB.Recordset and then rs = connection_name.Execute ("EXEC uspRecipeNote @IngString OUTPUT, " & intMixID & ";"). Commented Apr 1, 2016 at 17:53

2 Answers 2

5

String parameters need to be defined with a (maximum) length, e.g.,

cmd.Parameters.Append cmd.CreateParameter("@IngString", adVarChar, adParamOutput, 255)
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, but when I have tried that, I get the error: "Procedure or function uspRecipeNote has too many arguments specified." Does this provide a clue?
It did get past adding the parameter, but now fails at "cmd.Execute" with the error just above.
I dunno, I just tried it (code here) and it works for me. Is it possible that somewhere along the line @IngString got mixed up with @lngString? Or maybe there are multiple versions of uspRecipeNote under different schemas?
Thank you so much. It was a problem with my command object, which I was reusing, as I have many times before. This time I failed to clear it properly, which explains some of the odd behavior, like "too many arguments." Oh, the joys...
Ah, okay. Reusing ADODB.Command objects is not a recommended practice as strangeness may ensue, and not just for that reason (as I recall).
0

Thanks to all who helped try to solve my problem. It turns out that it was a problem with my command object, not the SP or the VBA (except for needing the length for the varchar parameter - thanks, Gord). Everything works just fine now!

Comments

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.