Invoking parametrized st procedure from vba

A

Alex

I'm looking for a piece of code that could show me how to call a stored
procedure with parameters from Visual Basic (Access).
 
N

Newbie

Below is some code that I use to create a recordset based on a stored
procedure - the variables are public and are set before running the
following code:

Set cn = New ADODB.Connection
Set cmd1 = New ADODB.Command
Set rsData = New ADODB.Recordset

cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=MIS;Data Source=D5QW8K0J"
cn.CursorLocation = adUseClient
cn.Open

With cmd1
Set .ActiveConnection = cn
.CommandText = "SchedByCell"
.CommandType = adCmdStoredProc
Set params = .Parameters
End With

params.Append cmd.CreateParameter("@RETURN_VALUE", adInteger,
adParamReturnValue, 0)
params.Append cmd.CreateParameter("@CellFrom", adVarChar, adParamInput, 16)
params.Append cmd.CreateParameter("@CellTo", adVarChar, adParamInput, 16)
params.Append cmd.CreateParameter("@DateFrom", adDBTimeStamp, adParamInput,
0)
params.Append cmd.CreateParameter("@DateTo", adDBTimeStamp, adParamInput, 0)

params("@CellFrom") = mCellFrom
params("@CellTo") = mCellTo
params("@DateFrom") = mDateFrom
params("@DateTo") = mDateTo

Set rsData = cmd1.Execute

HTH

A
 

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