title: Creating Parameterized SQL Queries in Excel 2010 with VBA
body: <p>I came across the following link:</p>
  
  <p><a href="http://www.informit.com/guides/content.aspx?g=sqlserver&amp;seqNum=135" rel="nofollow">http://www.informit.com/guides/content.aspx?g=sqlserver&amp;seqNum=135</a></p>
  
  <p>In it, they list relatively simple code to query the SQL Database from Excel VBA. </p>
  
  <pre><code>' Declare the QueryTable object
  Dim qt As QueryTable
  
  ' Set up the SQL Statement
  sqlstring = "select au_fname, au_lname from authors"
  
  ' Set up the connection string, reference an ODBC connection
  ' There are several ways to do this
  ' Leave the name and password blank for NT authentication
  connstring = _
   "ODBC;DSN=pubs;UID=;PWD=;Database=pubs"
  
  ' Now implement the connection, run the query, and add
  ' the results to the spreadsheet starting at row A1
  With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=sqlstring)
   .Refresh
  End With
  'Save and close the macro, and run it from the same menu you accessed in step 2.
  </code></pre>
  
  <p>This works fine. However, I want to be able to pull a value(s) back as a variable instead of dumping it to Excel. </p>
  
  <p>Can someone assist me with that? I've tried looking for Excel VBA SQL Tutorials, but it seems that half the code I find doesn't work (perhaps because I don't understand it well enough). </p>