calling stored procedure from vba code

hfs

Registered User.
Local time
Today, 08:39
Joined
Aug 7, 2013
Messages
47
I have code for calling stored procedure with parameters,which is as follows


Code:
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Dim IdValueToProcess As Long

IdValueToProcess = 221177  ' test data
    Debug.Print (IdValueToProcess)
Set qdf = CurrentDb.CreateQueryDef("")
qdf.ReturnsRecords = True
qdf.Connect = "ODBC;Description=pending;DRIVER=SQL Server;SERVER=BELQA;UID=ha;Trusted_Connection=Yes;"
               
       
qdf.SQL = "EXEC dbo.[spItemDesc] " & IdValueToProcess
Set rst = qdf.OpenRecordset(dbOpenDynaset)
'objConnection.Open provStr

 just to make sure we got a result
[COLOR="Red"]Debug.Print rst!ProductDesc1
Debug.Print rst!ProductDesc2[/COLOR]
rst.Close
Set rst = Nothing
qdf.Close
Set qdf = Nothing


and my stored procedure is

Code:
ALTER PROCEDURE [dbo].[spItemDesc]

	@ItemNo varchar(200) ,

AS
BEGIN

	set nocount on ;

select ProductDesc1,ProductDesc2 from ProductDatabase.dbo.tblProductInfo where ProductNumber = @ItemNo



END

the error comes on debug.print(rst!ProductDesc1)
and it says "Item not found in the collection"

?

Thanks in advance
 
code worked,forgot to write down the database name in connection string!
....
 

Users who are viewing this thread

Back
Top Bottom