title: VBA/SQL missing operator in query expression 'Count (distinct)
body: <p>I have a query that is inserted in my VBA code and I'm getting a similar missing an operator message. Here is the query:</p>
  
  <pre><code>SELECT mtn.*  
  FROM ( 
  SELECT PATIENT_KEY, RENDERING_PROVIDER_KEY 
  FROM [claim_detail$] 
  WHERE CPT_HCPS_PROC_CD IN ('82330', '82374', '82435', '82565', '82947', '84132', '84295', '84520') 
  GROUP BY PATIENT_KEY, RENDERING_PROVIDER_KEY HAVING COUNT(DISTINCT CPT_HCPS_PROC_CD) = 8) AS pat_matches 
  INNER JOIN [claim_detail$] mtn ON 
  mtn.PATIENT_KEY = pat_matches.PATIENT_KEY AND 
  mtn.RENDERING_PROVIDER_KEY = pat_matches.RENDERING_PROVIDER_KEY 
  WHERE mtn.CPT_HCPS_PROC_CD IN ('82330', '82374', '82435', '82565', '82947', '84132', '84295', '84520'); 
  </code></pre>
  
  <p>It is inserted in the code as:</p>
  
  <pre><code>query = "SELECT mtn.* " &amp;_
  "FROM ( " &amp;_
  "SELECT PATIENT_KEY, RENDERING_PROVIDER_KEY " &amp;_
  "FROM [claim_detail$] " &amp;_
  "WHERE CPT_HCPS_PROC_CD IN ('82330', '82374', '82435', '82565', '82947', '84132', '84295', '84520') " &amp;_
  "GROUP BY PATIENT_KEY, RENDERING_PROVIDER_KEY HAVING COUNT(DISTINCT CPT_HCPS_PROC_CD) &gt;= 8) AS pat_matches " &amp;_
  "INNER JOIN [claim_detail$] mtn ON " &amp;_
  "mtn.PATIENT_KEY = pat_matches.PATIENT_KEY AND " &amp;_
  "mtn.RENDERING_PROVIDER_KEY = pat_matches.RENDERING_PROVIDER_KEY " &amp;_
  "WHERE mtn.CPT_HCPS_PROC_CD IN ('82330', '82374', '82435', '82565', '82947', '84132', '84295', '84520');" 
  </code></pre>
  
  <p>The message I'm getting is</p>
  
  <p>Microsoft Access Database Engine (91, 2) : Syntax error (missing operator) in query expression 'COUNT(DISTINCT CPT_HCPS_PROC_CD) = 8'.</p>
  
  <p>Any help is appreciated.</p>