3

I can verify that my VBA code is executing the stored procedure at the server but I'm unable to get the recordset back into Excel.

Set con = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset

con.Open "Provider=SQLOLEDB;Data Source=" & ServerName & ";...."//works 
set rs = cmd.Execute(, SP_Param, adCmdStoredProc) // executes
If rs.EOF = False Then WSP1.Cells(4, 1).CopyFromRecordset rs
//tosses Operation is not allowed when the object is closed.

I've tried using the SQLOLEDB provider but am unable to get through to the stored procedure using that.

Relevant references:

  • ActiveX Data Object Recordset 6.0 Lib
  • ActiveX DataObjects 6.1
  • ActiveX Remote Data Services 6.0
2
  • Any chance there is no records in table ? Commented Oct 11, 2013 at 20:25
  • What's your stored proc? Commented Oct 11, 2013 at 20:55

2 Answers 2

5

Add a SET NOCOUNT ON to the beginning of your SQL Stored Procedure.

Sign up to request clarification or add additional context in comments.

Comments

2

I doubt this is the problem but you should try setting NOCOUNT ON in the proc to make sure that is not the problem.

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.