calling stored procedure from vba access gives run time error

hfs

Registered User.
Local time
Yesterday, 17:29
Joined
Aug 7, 2013
Messages
47
I am trying to call a stored procedure from access ,but it is giving me this runtime error :

Code:
2147217900
Syntax error or access voilation
I am doing this first time so i dont know about how to pass parameters (IN and OUT)..

My code is

Code:
Public Sub createDataToAnalyze()


Dim objConnection As New ADODB.Connection

Dim objCom As ADODB.Command
Dim param1 As String
'Dim param2 As String

'Dim param3 As String

Dim provStr As String

Set objCom = New ADODB.Command

objConnection.Provider = "sqloledb"

provStr = "Data Source=BEA09;" & "Initial Catalog=Pending_ReviewsSQL;User ID=" & Environ("username") & ";Trusted_Connection=Yes;"
objConnection.Open provStr

With objCom

.ActiveConnection = objConnection
param1 = "300817"
.CommandText = "[ItemDesc]" & param1
.CommandType = adCmdStoredProc

Set param3 = objCom.CreateParameter("@desc1", adVarChar, adParamOutput, 220, adParamReturnValue)
objCom.Parameters.Append param3
Set param2 = objCom.CreateParameter("@desc2", adVarChar, adParamOutput, 220, adParamReturnValue)
objCom.Parameters.Append param2


Debug.Print (.CommandText)
Debug.Print (param3)
Debug.Print (param2)
objCom.Execute


End With
End Sub

when i print .CommandText it shows me
{ call [ItemDesc]300817(?, ?) }

My stored procedure is below :
Code:
USE [Pending_ReviewsSQL]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =================
ALTER PROCEDURE [ItemDesc]
	
	
	@ItemNo varchar(200) ,
	@desc1 varchar(220) out,
	@desc2 varchar(220)out
	
AS
BEGIN
	
	SET NOCOUNT ON;

    
select @desc1 = ProductDatabase.dbo.tblProductInfo.ProductDesc2,@desc2 = ProductDatabase.dbo.tblProductInfo.ProductDesc2 
from belqcdata01.ProductDatabase.dbo.tblproductinfo
where ProductDatabase.dbo.tblproductinfo.ProductNumber = @ItemNo




END

Need help with this...
Thanks
 
Your fifth argument of CreateParameter is invalid. You are trying to apply a ParameterType Enum to an Output Parameter. Leave it empty.

I have never seen a parameter passed ike this and I very much doubt it is valid.
.CommandText = "[ItemDesc]" & param1

Normally it would be added to the parameters collection.
 

Users who are viewing this thread

Back
Top Bottom