I have a very straight forward and simple Stored Procedure accepting 1 parameter. When I called the sp from VBA, I got the below error from command.Execute
:
-2147217887 [MySQL][ODBC 5.3(w) Driver][mysqld-5.7.31-log]Invalid parameter type
However, I cannot determine what parameter type is incorrect from my view. I'm really running out of wits
Update:
Excel VBA MySql parameterised update 'invalid parameter type' has the exact same error, however, the answer is for non- Stored Procedure calls.
My code is like the below
Stored Procedure:
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_load_visit`(
IN _nid char(18)
)
BEGIN
SET @query = concat("
select visiting_date, method, visiting_details from tbl_visit where visiting_customer=? order by visiting_date asc;
");
PREPARE stmt FROM @query;
SET @_nid = _nid;
EXECUTE stmt USING @_nid;
DEALLOCATE PREPARE stmt;
END
VBA code:
Public Sub formControl_Update()
Dim cmd As New ADODB.Command
Dim conn As ADODB.Connection
Dim prm As ADODB.Parameter
Dim strConn As String
Dim strSQL As String
strConn = "Driver={MySQL ODBC 5.3 Unicode Driver};Server=127.0.0.1;Database=jkydb1;Uid=admin;pwd=123456"
conn.Open strConn
command.ActiveConnection = myConn
command.CommandText = "sp_load_visit"
command.CommandType = adCmdStoredProc
command.CommandTimeout = 10
command.NamedParameters = True
command.Prepared = True
Set prm = command.CreateParameter("_nid", adChar, adParamInput, 18, cell_customer_nid.value)
command.Parameters.Append prm
Set rs = command.Execute
End Sub
The post I've read:
Parameter Object
run stored procedure and return values from VBA