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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call Stored Procedure and pass 1 parameter

Status
Not open for further replies.

slipfrase

Programmer
Feb 23, 2004
16
GB
Hi Folks,

I'm looking for an example of calling a stored procedure and pass 1 parameter via vba. I have searched all the forums and can't seem to find a simple example. My stored procedure is called deleteccf (which deletes a record in a table called ccf)

The code is as follows:

Alter Procedure "DeleteCCF"
@ccfid int
As
DELETE

FROM
dbo.CCF
WHERE
ID = @ccfid
RETURN

I am looking to run the procedure from a button on a form and pass the value of a field call txtid to the @ccfid, in effect deleting the required record. I am wanting to do this through vba because I don't want the user to get prompted to delete a record.

Thanks in advance....

Fraser
 
Folks, Figured it out myself, code below if anyone cares:


'sets the variable ccfid1 to the value of the text box
Dim ccfid1 As Integer
TxtID.SetFocus
ccfid1 = TxtID.Text

Dim rst As New ADODB.Recordset
Dim cmd As New ADODB.Command

'Specify properties of the Command object.
With cmd
.ActiveConnection = CurrentProject.BaseConnectionString
.CommandType = adCmdStoredProc
.CommandText = "deleteccf"
.Parameters.Refresh
.Parameters(1) = ccfid1
Set rst = .Execute
End With

Me.Requery
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top