title: MS Access VBA: Combine 2 SQL statements with a LEFT JOIN
body: <p>Hi all and thanks in advance for your help!
  I am trying to use a JOIN to combine a fitlered SQL statement with a table in order to populate a combobox (makes sense?)</p>
  
  <p>Here is the main SQL query:</p>
  
  <pre><code>MainSQLquery = "SELECT QuotationID, QuoteDate, EmployeeID FROM TestTable1"
  </code></pre>
  
  <p>I want to write a statement to use this with another table like so:</p>
  
  <pre><code>SELECT EmployeeID, EmployeeName
  FROM MainSQLquery LEFT JOIN EmployeeTable
  GROUP BY EmployeeID
  </code></pre>
  
  <p>But I can't get it right. I get a "Syntax error in FROM clause" even with something as simple as:</p>
  
  <pre><code>ComboSQL = "SELECT EmployeeID FROM " &amp; MainSQLQuery
  Me.Combo2.RowSource = ComboSQL
  </code></pre>
  
  <p>Do you guys know any way to do this?</p>
  
  <p>*******BACKGROUND**********</p>
  
  <p>For those of you who wants to see the bigger picture, I have a subform showing a list of quotations and based on a dynamic SQL statement, it is filetered with a WHERE clause based on different inputs and it looks like this when displayed:</p>
  
  <pre><code>QuoteID   Quote date    Employee ID
  1         10/13          1
  2         10/13          2
  3         10/13          2
  4         09/18          1
  5         08/10          2
  6         07/16          3
  7         06/27          3
  </code></pre>
  
  <p>On the main form, I have comboboxes that I use to filter this subform, which works perfectly. But I also need my comboboxes to be filtered the same way as the subform content and without having any duplicate (that's the only thing I can't do right now).</p>
  
  <p>So far I use the same filtered SQL query for the subform and all the comboboxes, so instead of having a neat Employee combobox that looks like this (with the example above):</p>
  
  <pre><code>1
  2
  3
  </code></pre>
  
  <p>I get that instead (same as the subform):</p>
  
  <pre><code>1
  2
  2
  1
  2
  3
  3
  </code></pre>
  
  <p>My idea is to have a main SQL query for the subform, and another SQLquery based on the main one for the comboboxes, something like that:</p>
  
  <pre><code>SELECT EmployeeID, EmployeeName
  FROM MainSQLquery LEFT JOIN EmployeeTable
  GROUP BY EmployeeID
  </code></pre>
  
  <p>if I could get this working, the filter would still be built in the mainSQL and I could group the EmployeeID field without problem.</p>
  
  <p>I guess it should be fairly simple, but I can't get it right, there is something I don't know about using an SAL as source of another.</p>
  
  <p>(I wish I could post pictures or a database sample, but a paranoid guy got my previous post deleted because of that, so it will have to do with text only, sorry about that)</p>