PDA

View Full Version : Passing Parameters To A Stored Procedure Using VBA



mattster1010
03-25-2011, 04:22 AM
Morning All,

I'm using the below vba code to pass parameters to a stored procedure called "Local_Send_Doc":

'Dim Cmd1 As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim intTemp As Integer

Set Cmd1 = New ADODB.Command

Cmd1.ActiveConnection = cn
Cmd1.CommandText = "Local_Send_Doc"
Cmd1.CommandType = adCmdStoredProc

Cmd1.Parameters.Refresh
Cmd1.Parameters("@USERID").Value = "smithm"
Cmd1.Parameters("@INVNUMB").Value = "OP/I976893"
Cmd1.Parameters("@TYPE").Value = "Invoice"
Set rs = Cmd1.Execute()

It throws up a type mismatch error on the line highlighted in red. Can anyone see any obvious problems with the code?

Regards,

Mattster

OBP
03-26-2011, 05:35 AM
Are you sure that UserID is a Text field or variable?
That error occurs when you try and assign a text to a Number type field or variable.

mattster1010
03-27-2011, 10:48 AM
Hi OBP,

You were right. The problem was with the parameter not being set to Char (20).

I'll post the correct code up on the site for an example. The code is working nicely now.

Thank you for your help.

Regards,

Mattster