
Append fields to a disconnected recordset created from SQL stored procedure
I have tried everything I can think of as well as many tips I found on
Dejanews, still no luck. I am trying to add two fields to a disconnected
recordset which was generated from an SQL 7.0 stored procedure which takes a
lot of parameters.
The function is included below, the error I get is :
The operation requested by the application is not allowed in this context.
I have indicated which line in the code causes this error. Can anyone point
out what I am missing? The function works great if the two offending lines
of code are removed.
Thanks in advance.
Rob
Function Test(sName As String, _
datStart As Date, _
datEnd As Date, _
iLowInt As Integer, _
iHighInt As Integer, _
iSun As Integer, _
iMon As Integer, _
iTue As Integer, _
iWed As Integer, _
iThu As Integer, _
iFri As Integer, _
iSat As Integer) As ADODB.Recordset
Dim objRS As ADODB.Recordset
Dim objCommand As ADODB.Command
Dim objParam As ADODB.Parameter
Set objRS = New ADODB.Recordset
Set objCommand = New ADODB.Command
Set objParam = New ADODB.Parameter
Set objCommand.ActiveConnection = objConn
objCommand.CommandText = "Test"
'set up each parameter and append it to the command objects parameters
collection
Set objParam = objCommand.CreateParameter("name", adVarChar,
adParamInput _
, 10, sName)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("start_date", adDBTimeStamp,
adParamInput _
, 8, datStart)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("end_date", adDBTimeStamp,
adParamInput _
, 8, datEnd)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("lowint", adInteger,
adParamInput _
, 4, iLowInt)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("highint", adInteger,
adParamInput _
, 4, iHighInt)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("sun", adInteger, adParamInput
_
, 4, iSun)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("mon", adInteger, adParamInput
_
, 4, iMon)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("tue", adInteger, adParamInput
_
, 4, iTue)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("wed", adInteger, adParamInput
_
, 4, iWed)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("thu", adInteger, adParamInput
_
, 4, iThu)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("fri", adInteger, adParamInput
_
, 4, iFri)
objCommand.Parameters.Append objParam
Set objParam = objCommand.CreateParameter("sat", adInteger, adParamInput
_
, 4, iSat)
objCommand.Parameters.Append objParam
'Execute the command object and create recordset
objRS.CursorLocation = adUseClient
objRS.Open objCommand, , adOpenStatic, adLockBatchOptimistic,
adCmdStoredProc
Set objRS.ActiveConnection = Nothing
'These lines causes the following error:
'The operation requested by the application is not allowed in this
context.
objRS.Fields.Append "NewField1", adDouble
objRS.Fields.Append "NewField1", adDouble
'return recordset to caller
Set Test = objRS
'destroy objects
Set objCommand = Nothing
Set objParam = Nothing
Set objRS = Nothing
End Function