Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a Stored Procedure with a parameter

Status
Not open for further replies.

katoc

Programmer
Feb 15, 2005
52
US
I need help executing a stored procedure from an Access form.

The stored procedure is already declared in the SQL Server as:

Code:
CREATE PROCEDURE [spSK_Delete] 
@recToDelete int
AS
delete from [logs] 
where logid = @recToDelete
GO

There is a button on my form called 'delete_Log' and the code behind it is:

Code:
Dim cn As New ADODB.Connection
    Dim objcmd As New ADODB.Command

    With cn
        .Provider = "msdasql"
        .Properties("data source").Value = "ODBC;DSN=myCompany;UID=sa;PWD=;DATABASE=LogInventory"
        .Open
    End With
    objcmd.CommandText = "sp_SKDelete"
    objcmd.CommandType = adCmdStoredProc
    objcmd.ActiveConnection = cn
    objcmd(1) = sel_Log.Value
    objcmd.Execute
    
    cn.Close
    Set cn = Nothing
    Set objcmd = Nothing

I stops on the line: objcmd(1) = sel_Log.Value and says "Item cannot be found in the collection corresponding to the requested name or ordinal."

What am I doing wrong?

Thanks.
 
Never mind. I found out that I needed to run the generated sql script from the Enterprise Manager. It's working perfectly now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top