The "Type Mismatch" error you are encountering in your Access SQL query when using the InStrRev function could be due to how Access evaluates expressions in the HAVING clause. The HAVING clause is used to filter records after the GROUP BY operation, and sometimes the evaluation of expressions can lead to unexpected results, especially if there are null values or data type inconsistencies in the fields being compared.
In your first example, the expression 1 * InStrRev ([Query21].[Naam tegenrekening], "Broek") is evaluated, and if it results in a null or unexpected value, it may trigger the type mismatch error. However, when you add an additional condition (e.g., AND ((mutations.grootboek) = 4120)), it may change the context of evaluation, allowing Access to handle the expression without error.
To troubleshoot this issue:
- Ensure that
[Query21].[Naam tegenrekening]does not contain null values, as this can lead to type mismatches when performing string operations. - Consider using
Nz()function to handle null values, for example:Nz(1 * InStrRev([Query21].[Naam tegenrekening], "Broek"), 0)to provide a default value in case of null. - Check the data types of the fields involved in the comparison to ensure they are compatible.
By addressing these points, you should be able to resolve the type mismatch error in your query.
References: