stanl
asked on
Adodb Command.Execute() - type value error
I was experimenting with ADO and the "CREATE PROC" SQL to create stored procedures in an Access 2002 database. I started with an example that used Northwind.
I then wrote a short VBS function to execute the Procedure via the adodb.command object - I first tried it by using CreateParameter() and Append, but kept getting a type value error when executing - however, if I pass the parameters to the function then include them as an optional array (the 2nd parm of cmd.Execute() ) it works fine. Most of the examples I have seen don't use the 2nd parameter, so I was wondering, is there a bug in Jet 4.0? -
========================== ========== ==
function runcmd(nRec,cName)
' this is the query in Access
'PARAMETERS inProductID Long, inProductName Text ( 40 );
'UPDATE Products SET Products.ProductName = inProductName
'WHERE (((Products.ProductID)=[in ProductID] ));
Set conn = CreateObject("adodb.Connec tion")
conn.Open("PROVIDER=Micros oft.Jet.OL EDB.4.0; Data Source=C:\Program Files\Microsoft Office\Office10\Samples\no rthwind.md b;")
Set cmd = CreateObject("adodb.Comman d")
cmd.ActiveConnection = conn
cmd.CommandText = "procProductsUpdateItem"
cmd.CommandType = 4
' if the next 3 lines are executed you get a "Type Value" error
cmd.Parameters.Append cmd.CreateParameter("inPro ductID",13 9,1,,2)
cmd.Parameters.Append cmd.CreateParameter("inPro ductName", 129,1,40," New Chang")
cmd.Execute , , adExecuteNoRecords
' however, if you pass the function parameters to an array, it works fine
'cmd.Execute ,Array(nRec,cName), adExecuteNoRecords
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
conn.close
Set conn = Nothing
runcmd = 0
end function
========================== ========== =====
stan
I then wrote a short VBS function to execute the Procedure via the adodb.command object - I first tried it by using CreateParameter() and Append, but kept getting a type value error when executing - however, if I pass the parameters to the function then include them as an optional array (the 2nd parm of cmd.Execute() ) it works fine. Most of the examples I have seen don't use the 2nd parameter, so I was wondering, is there a bug in Jet 4.0? -
==========================
function runcmd(nRec,cName)
' this is the query in Access
'PARAMETERS inProductID Long, inProductName Text ( 40 );
'UPDATE Products SET Products.ProductName = inProductName
'WHERE (((Products.ProductID)=[in
Set conn = CreateObject("adodb.Connec
conn.Open("PROVIDER=Micros
Set cmd = CreateObject("adodb.Comman
cmd.ActiveConnection = conn
cmd.CommandText = "procProductsUpdateItem"
cmd.CommandType = 4
' if the next 3 lines are executed you get a "Type Value" error
cmd.Parameters.Append cmd.CreateParameter("inPro
cmd.Parameters.Append cmd.CreateParameter("inPro
cmd.Execute , , adExecuteNoRecords
' however, if you pass the function parameters to an array, it works fine
'cmd.Execute ,Array(nRec,cName), adExecuteNoRecords
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
conn.close
Set conn = Nothing
runcmd = 0
end function
==========================
stan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It turned out that adNumeric and adVarChar were needed, and although you first response was incorrect, it got me to focus on where the error was actually occuring.
ASKER
P.S. I amd using the Jet SP8 on XP.