title: Insert Into Table from Excel via VB button to stored procedure with Variables
body: <p>I have a simple table <code>AMC_GW_TESTTABLE</code> with two columns, <em>name</em> nvarchar(20) and <em>phone</em> nvarchar(12).  I also have a simple stored procedure with two variables.</p>
  
  <pre class="lang-sql prettyprint-override"><code>create procedure AMC_GW_TESTSP (@name nvarchar(20),
                                  @phone nvarchar(12)) as
  insert into AMC_GW_Testtable (name,phone)
  values (@name, @Phone)
  </code></pre>
  
  <p>I have been able to get a button in Excel to create the command:</p>
  
  <pre><code>exec dbo.amc_gw_testsp 'fred' '620-555-1212'
  </code></pre>
  
  <p>But it does not execute it.  I copy this to my SSMS exactly like it and execute it and it works fine.  Any ideas?</p>
  
  <p>VBA code</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub Button1_Click()
  
      Dim conn As ADODB.Connection
      Dim cmd As ADODB.Command
      Dim connStr As String
      Dim param As ADODB.Parameter
      Dim param2 As ADODB.Parameter
  
      connStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;" _
                &amp; "Initial Catalog=am_app);Data Source=bcu-sql-01"
  
      Set conn = New ADODB.Connection
      conn.ConnectionString = connStr
      conn.Open
  
      Set cmd = New ADODB.Command
      With cmd
          .ActiveConnection = conn
          .CommandType = adCmdStoredProc
          .CommandText = "AMC_GW_TESTSP"
          Set param = .CreateParameter("@name", adVarChar, adParamInput, 20, "Christopher")
          .Parameters.Append param
          Set param2 = .CreateParameter("@phone", adVarChar, adParamInput, 12, "0123456789")
          .Parameters.Append param
  
        .Execute
      End With
  
      conn.Close
      Set cmd = Nothing
      Set conn = Nothing
  
  End Sub
  </code></pre>