get recordset from cmd object

  • Thread starter Thread starter smk23
  • Start date Start date
S

smk23

I would like to return a recordset from a stored procedure using the cmd
object:

Set mCmd = New ADODB.Command
With mCmd
.ActiveConnection = mConn
.CommandText = SelectCommandText
.CommandType = adcmdStoredProc
Set mrst = New ADODB.Recordset
Set mrst = .Execute

I get an error "syntax error or access violation" when I try to execute. I
have code that checks whether mConn is open prior to this and it is. When I
take the .CommandText and run it in Query Analyzer, it executes fine. What
can I do to determine what the issue is?

Thanks so much!
 
Assuming that mConn is an instantiated Connection object, you need

Set .ActiveConnection = mConn

In actual fact, you don't need the Set mrst = New ADODB.Recordset statement,
as the next line should properly instantiate mrst.
 
Back
Top