I'm using a form with combo boxes to apply filters on an append query. I have used the following SQL instruction that works if I run as a query but if I run in VB using CurrentDb.Execute(SQL string) I get the following error.
Run time error '3122':
You tried to execute a query that does not include the specified expression 'Channel' as part of an aggregate function.
The SQl is
INSERT INTO grp1Source ( Channel, [SumOfGross Margin] )SELECT Z0010_select_only_sales.Channel, Sum(Z0010_select_only_sales.[Gross Margin]) AS [SumOfGross Margin] FROM Z0010_select_only_sales
WHERE (((Z0010_select_only_sales.company) = forms!form2!cpyCombo OR forms!form2!cpyCombo IS NULL) )
GROUP BY Z0010_select_only_sales.Channel
HAVING ((Z0010_select_only_sales.Channel) = forms!form2!cnlCombo OR forms!form2!cnlCombo IS NULL);
There are other filters in the WHERE statement but I have removed them on here to make it easier to read and they are just repeats of the first one with different fields etc.
What am i doing wrong?!
Run time error '3122':
You tried to execute a query that does not include the specified expression 'Channel' as part of an aggregate function.
The SQl is
INSERT INTO grp1Source ( Channel, [SumOfGross Margin] )SELECT Z0010_select_only_sales.Channel, Sum(Z0010_select_only_sales.[Gross Margin]) AS [SumOfGross Margin] FROM Z0010_select_only_sales
WHERE (((Z0010_select_only_sales.company) = forms!form2!cpyCombo OR forms!form2!cpyCombo IS NULL) )
GROUP BY Z0010_select_only_sales.Channel
HAVING ((Z0010_select_only_sales.Channel) = forms!form2!cnlCombo OR forms!form2!cnlCombo IS NULL);
There are other filters in the WHERE statement but I have removed them on here to make it easier to read and they are just repeats of the first one with different fields etc.
What am i doing wrong?!