You are embedding the variable's value into the SQL String in VBA. From a pure SQL perspective this value then becomes a hardcoded valued in the SQL. - But that remark was mainly directed towards OBP, who brought up the term
parameter, which he used somewhat imprecisely, not to say incorrectly.
My question to you, mojoes, remains:
Where/How do you run the query?
I understand you do it somewhere inside a Form_Load event procedure, but please show the VBA code that (supposedly) does it.
I still suspect you do not run this SQL at all. There are a couple of problems with your SQL concatenation in VBA that are not in-line with the problem description you posted.
Here are the problems I spotted:
1. A missing space after
SELECT
2. Another missing space after
myday
3. The column
t_desc2.idtaskname should not be in the GROUP BY. You are not using this column in the output, only its aggregation COUNT(
t_desc2.idtaskname).
I created a tutorial (text and video)
on building SQL Strings in VBA. I think this might be helpful to you.