Visual Basic Concepts
Using the same technique used with parameter queries in SELECT statements, you can also capture the output parameters from a procedure.
To capture output parameters
When the query has completed processing, retrieve the output parameter values from the rdoParameters collection.
This example executes a stored procedure that expects two input parameters and returns two output parameters along with a return value parameter. Note that the SQL query uses ODBC syntax in the rdoQuery, which is required if you intend to execute stored procedures that return output arguments.
Dim SQL As String, MyOutputVal1 As Variant
Dim MyOutputVal2 As Variant, MyRetValue As Variant _
rs As rdoResultset
Dim Ps As rdoQuery
' Use named arguments to open the connection.
Dim cn as New rdoConnection
With cn
.Connect = "dsn=Sequel;uid=;pwd=;database=workdb"
.EstablishConnection Prompt:=rdDriverNoPrompt
End With
' Use ODBC parameter argument syntax.
' Note each argument is identified
' with a ? character – one for the ReturnValue,
' one for each of the input arguments
' and one for each of the output arguments.
SQL = "{? = call TestOutputRS (?, ?, ?, ?) }"
' Create reusable rdoQuery.
Set Ps = cn.CreateQuery("PsTest", SQL)
' Set Parameter "direction" for each output
' and return value parameter.
Ps(0).Direction = rdParamReturnValue
Ps(3).Direction = rdParamOutput
Ps(4).Direction = rdParamOutput
' Set the input argument values.
Ps.rdoParameters(1) = "Test%"
Ps.rdoParameters(2) = 1
' Create the result set and populate the Ps values.
Set rs = Ps.OpenResultset(rdOpenStatic)
MyRetValue = Ps(0) ' The return value argument.
MyOutputVal1 = Ps(3) ' The first output parameter.
MyOutputVal2 = Ps(4) ' The second output parameter.