Code:
Dim rs As ADODB.RecordSet
Set rs = New ADODB.RecordSet
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = cn 'global connection string
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "usp_GetItem"
with cmd.Parameters
.Item("@parm1") = parm1
.Item("@parm2") = parm2
End With
Set rs = cmd.Execute
If rs.EOF Then '<-- error here
functionName = DefaultValue
Else
functionName = rs!Item
End If
Set rs = Nothing
Set cmd = Nothing
Exit Function
The error is happening on rs.EOF. I get "Operation is not allowed when the object is closed" which is in reference to the closed record set that's returned from the cmd.Execute statement. The record that returns contains three fields, first has data, second is null, third is Item. Item is empty but not null. I have multitudes of other queries coded exactly the same way without this error. Why is it happening?