title: VBA SQL query with WHERE clause
body: <p>I'm trying to write VBA code to get SQL data into Excel. Everything works fine except the <code>WHERE</code> condition. I think the problem may be with quotation. This is my query:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub Engineering_Milestone()
  
  Dim v_project As String
  Dim cn  As ADODB.Connection
  Dim rs  As ADODB.Recordset
  Dim sql As String
  
  Set cn = New ADODB.Connection
  Set rs = New ADODB.Recordset
  
  v_project = Worksheets("Parameters").Range("B1").Value
  
  'cn.Open "Provider = x.1; Data Source=x; Initial Catalog=x; Integrated Security=x"
  
  
  cn.Open "Provider = Sx; Data Source=x; Initial Catalog=x; Integrated Security=x"
  
  Worksheets("Engineering_Milestone").Range("A2:G5000").ClearContents
  
  sql = " SELECT A.ENGINEER_ID, B.[Description], B.BUDGET_APPROVED, A.MILESTONE, A.[DESCRIPTION], A.PCT_COMPLETE, A.SCHEDULE_DATE FROM X as A  Inner Join X as B on A.ENGINEER_ID = B.ENGINEER_ID WHERE B.Project_ID = " &amp; "'" &amp; v_project &amp; "'" and A.Project_ID = " &amp; "'" &amp; v_project &amp; "'"
  
  rs.Open sql, cn
  
  Sheets("Engineering_Milestone").Cells(2, 1).CopyFromRecordset rs
  
  rs.Close
  cn.Close
  
  End Sub
  </code></pre>
  
  <p>It works fine when the SQL query has one condition i.e ...<code>where B.Project_ID = " &amp; "'" &amp; v_project &amp; "'"</code> (without second condition -> <code>and A.Project_ID = " &amp; "'" &amp; v_project &amp; "'"</code>).</p>
  
  <p>I'm very new to this so would be grateful if anyone can help...Many thanks.</p>