Link to home
Start Free TrialLog in
Avatar of stanl
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)=[inProductID]));


Set conn = CreateObject("adodb.Connection")
conn.Open("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb;")
Set cmd = CreateObject("adodb.Command")
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("inProductID",139,1,,2)
cmd.Parameters.Append cmd.CreateParameter("inProductName",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
ASKER CERTIFIED SOLUTION
Avatar of rajaloysious
rajaloysious

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stanl
stanl

ASKER

Nope - now the error says "Paramater Object is improperly defined, inconsistenet or imcomplete information provided" -

P.S. I amd using the Jet SP8 on XP.
Avatar of stanl

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.