title: Error: "Command text was not set for the command object" when running a Stored Procedure from SQL on VBA
body: <p>I'm trying to run a stored procedure on VBA using the following VBA code:
  Please can someone advise: I get the error at "rs.Open".</p>
  
  <pre><code>Sub connection()
  
     Dim Conn As ADODB.connection
      Dim ADODBCmd As ADODB.Command
      Dim rs As ADODB.Recordset
      Dim i As Integer
      Dim constring As String
      Dim location As String  'the server
      Dim password As String
  
  
  location = "10.103.98.18" 
  password = "password"
  constring = "Provider=SQLOLEDB; Network Library=DBMSSOCN;Data Source=" &amp; location &amp; ";Command Timeout=0;Connection Timeout=0;Packet Size=4096; Initial Catalog=ElColibri; User ID=Analyst1; Password=password;"
  
  
  
  Set Conn = New ADODB.connection
  Conn.connectionString = constring
  'On Error GoTo ConnectionError
  Conn.Open
  
  
  
  
  
  
  'loginstatus = False
  'Exit Sub
  
  
  'errorhandl0
  'ConnectionError:
  'MsgBox "Not possible to log in. Have you entered the correct password?"
  
  'open recordset
  Set ADODBCmd = New ADODB.Command
  ADODBCmd.ActiveConnection = Conn
  ADODBCmd.CommandTimeout = 1200
  ADODBCmd.CommandText = ["ukrmc.dbo.FridayCommentary"]
  ADODBCmd.CommandType = 4 'adCmdStoredProc
  ADODBCmd.Execute
  Set rs = New ADODB.Recordset
  rs.ActiveConnection = Conn
  rs.Open
  
  Conn.Close
  Set Conn = Nothing
  Set ADODBCmd = Nothing
  
  'Paste to spreadsheet
  ThisWorkbook.Worksheets("macrotest").Range("a2").CopyFromRecordset
  'Set rs = conn.Execute(Query)
  rs.Close
  Set rs = Nothing
  
  
  End Sub
  </code></pre>
  
  <p>To me the code makes logical sense to me so I am not sure what the error means. Because to me, I have set text for the command object. </p>