title: Attempting to dynamically pass parameters to a stored procedure from excel 2013 calling DB2 mainframe
body: <p>I have a requirement to dynamically pass parameter to a called SP which pulls data from the mainframe.  </p>
  
  <p>My excel connection string is: </p>
  
  <pre><code>DRIVER={IBM DB2 ODBC DRIVER};UID=k9751x1;PWD=********;MODE=SHARE;DBALIAS=RISCTEST;
  </code></pre>
  
  <p>The command text is: </p>
  
  <pre><code>call K9751DB.SP_GETRTSDB_BYDBTSNOPTLIKEDTTM('', '', '','2017-10-01 23:25:59.999999','2')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kQo6T.png" rel="nofollow noreferrer">Connection Properties, for reference</a></p>
  
  <p>I'm attempting to pass the first 3 parameters: <code>LPARSSID</code>, <code>DBNAME</code>, <code>TSNAME</code></p>
  
  <p>I've created the following VBA code and assigned an activeX button. The code appears to debug fine. but when I click on the button noting appears to happen.</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Dim LPARSSID As String 'Declare LPARSSID as String
  Dim DBNAME As String 'Declare DBNAME As String
  Dim TSNAME As String 'Declare TSNAME As String
  
  LPARSSID = Sheets("RTSbyDBTSDTE").Range("B2").Value  'Pass value from cell B2 to LPARSSID variable
  DBNAME = Sheets("RTSbyDBTSDTE").Range("B3").Value    'Pass value from cell B3 to DBNAME variable
  TSNAME = Sheets("RTSbyDBTSDTE").Range("B4").Value    'Pass value from cell B4 to TSNAME variable`
  
  Pass the Parameters values to the Stored Procedure used in the Data Connection
  With ActiveWorkbook.Connections("RISCTEST - ParmPass").ODBCConnection
  .CommandText = "call K9751DB.SP_GETRTSDB_BYDBTSNOPTLIKEDTTM('" &amp; LPARSSID &amp; "', '" &amp; DBNAME &amp; "', '" &amp; TSNAME &amp; "','2017-10-01 23:25:59.999999','2')"
  ActiveWorkbook.Connections("RISCTEST - ParmPass").Refresh
  
  End With
  End Sub
  
  Private Sub CommandButton21_Click()
  
  End Sub
  </code></pre>
  
  <p>Not sure if <code>ODBCConnection</code> is correct.</p>
  
  <p>I appreciate any suggestions you may have.</p>
  
  <p>Tku,
  Jeff A </p>