Executing a stored procedure?

G

Gene S.

Hello,

How do I call(execute) a stored procedure using code in an
event within a .adp?

Any help would be greatly appreciated!
Thanks in advance
 
S

Sylvain Lafontaine

The easiest way is to use ADO; for example:

Dim cmd As ADODB.Command
Set cmd = New ADODB.Command

cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "dbo.MyStoredProcedure"
cmd.Parameters.Append cmd.CreateParameter("@IdLigue", adInteger,
adParamInput, , IdLigue)
cmd.Execute , , adExecuteNoRecords

and here another one, still using the previous Cmd object :
....
cmd.CommandType = adCmdText
cmd.CommandText = "select * from dbo.MyTable where ..."

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockReadOnly

S. L.
 
A

Alex MRu

If your stored procedure is simple, you may also launch it as a sql
procedure:
docmd.runsql("....")
from queries, select new; design stored procedure. design your procedure.
You may obtain the .... from the icon SQL on the stored procedure design
menu (between icons grid and very sql syntax)
This is ok for simple procedures only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top