title: Access - "Data type mismatch in criteria expression" with VBA function
body: <p>I get error <em>Data type mismatch in criteria expression</em> when running this query.
  See below what I tried. Question is how can I investigate further to find the error?</p>
  <pre><code>SELECT qCalls.Senso, qCalls.Data, qCalls.Ora, qCalls.NumeroPulito, qCalls.Durata, qContactsOutlookPerCallsUNION.Azienda, IIf(Count([NOME])=1,First([NOME]),&quot;**nomi multipli**&quot;) AS Nome2
  FROM qCalls INNER JOIN qContactsOutlookPerCallsUNION ON qCalls.NumeroPulito = qContactsOutlookPerCallsUNION.Numero
  GROUP BY qCalls.Senso, qCalls.Data, qCalls.Ora, qCalls.NumeroPulito, qCalls.Durata, qContactsOutlookPerCallsUNION.Azienda
  ORDER BY qCalls.Data DESC;
  </code></pre>
  <p>Both <code>qCalls</code> and <code>qContactsOutlookPerCallsUNION</code> run correctly when called separately.
  There is no criteria expression (= WHERE clause, as I understand it) in my SQL. I then think the data type issue is on the <code>INNER JOIN</code> part but:</p>
  <ul>
  <li><code>qCalls.NumeroPulito</code> is a string, comes from: <code>CStr(Replace([Number],&quot;+39&quot;,&quot;&quot;)) AS NumeroPulito</code></li>
  <li><code>qContactsOutlookPerCallsUNION.Numero</code> is a string, it comes from: <code>IIf(IsNull([Phone]),Null,PulisciTelPerCalls([Phone])) AS Fisso</code> where <code>PulisciTelPerCalls()</code> is a VBA function which returns a <em>string</em></li>
  </ul>