Ok. We got a little farther. The sp executes and no error
requesting a parameter. I do get error stating that "Operation
not allowed when object is open." It is refering to the line - Set
oRs.ActiveConnection = Nothing.
Also, I hade the logic backwards for the parameter - = instead of <>.
I could create another connection just for executing the sp's.
This is what is working.
VB Code:
Public Function Exec_SPrs(ByRef oCnnS As ADODB.Connection, ByVal sp_Name As String, Optional ByVal sParam As String) As ADODB.Recordset '<RR 09/16/2003 - VB/OUTLOOK GURU> On Error GoTo No_Bugs Dim oRs As ADODB.Recordset Dim oCM As ADODB.Command Dim oParam As ADODB.Parameter Dim lRecs As Long Set oRs = New ADODB.Recordset Set oCM = New ADODB.Command Set oCM.ActiveConnection = oCnnS oCM.CommandType = adCmdStoredProc oCM.CommandText = sp_Name If sParam <> "" Then Set oParam = oCM.CreateParameter("@Task_No", adChar, adParamInput, 8, sParam) oCM.Parameters.Append oParam End If ' Set oRs = oCM.Execute(lRecs, sParam) Set oRs = oCM.Execute 'Works this way now Set Exec_SPrs = oRs Set oRs.ActiveConnection = Nothing 'Error here Set oParam = Nothing Set oCM = Nothing Exit Function No_Bugs: MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation, App.ProductName ' Resume End Function





Reply With Quote