MS Access Query

Mac1206

Board Regular
Joined
Jun 3, 2016
Messages
184
Could someone please let me know if my query is correct...I keep getting a syntax error?

iif(Sum([Assignment_test]![CountOfPlanNumber]+[Assignment_test]![InvComplete])=0, "Complete", "Incomplete"))) AS Expr2
FROM Assignment_test;
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Is this form code? It looks like a mishmash of raw sql + textbox elements. As raw SQL it's missing a "Select" and for form control its probably not right either. What are you trying to do?
 
Upvote 0
Is this form code? It looks like a mishmash of raw sql + textbox elements. As raw SQL it's missing a "Select" and for form control its probably not right either. What are you trying to do?

SELECT Assignment_test.Assignment, Assignment_test.BillGroup, Assignment_test.BillGroupID, Assignment_test.CountOfPlanNumber, Assignment_test.InvComplete, IIf(Sum([Assignment_test]![CountOfPlanNumber]+[Assignment_test]![InvComplete])=0,"Complete","Incomplete") AS Complete_Incomplete
FROM Assignment_test;

If [Assignment_test]![CountOfPlanNumber]+[Assignment_test]![InvComplete])=0 then I want Complete in the field and if not then Incomplete for the field row....
 
Last edited:
Upvote 0
Possibly,

Code:
SELECT 
	Assignment, 
	BillGroup, 
	BillGroupID, 
	CountOfPlanNumber, 
	InvComplete, 
	"Complete" AS Complete_Incomplete
FROM Assignment_test
WHERE
	Nz(CountOfPlanNumber,0) + Nz(InvComplete,0) = 0

UNION ALL

SELECT 
	Assignment, 
	BillGroup, 
	BillGroupID, 
	CountOfPlanNumber, 
	InvComplete, 
	"InComplete" AS Complete_Incomplete
FROM Assignment_test
WHERE
	Nz(CountOfPlanNumber,0) + Nz(InvComplete,0) <> 0

Also possible (with the return of IIF):
Code:
SELECT 
	Assignment, 
	BillGroup, 
	BillGroupID, 
	CountOfPlanNumber, 
	InvComplete, 
	IIF(Nz(CountOfPlanNumber,0) + Nz(InvComplete,0) = 0, "Complete", "Incomplete") AS Complete_Incomplete
FROM Assignment_test
 
Last edited:
Upvote 0
A syntax error is a very specific type of error. Is that the exact error, or is it about not having a field as part of an aggregate function?
You are trying to use an aggregate function (SUM) as a calculated field, but don't have any type of Totals query key words. I would expect this should look more like
Code:
SELECT Assignment_test.Assignment, Assignment_test.BillGroup, Assignment_test.BillGroupID, Assignment_test.CountOfPlanNumber,
Assignment_test.InvComplete, IIf(Sum([Assignment_test]![CountOfPlanNumber]+[Assignment_test]![InvComplete])=0,"Complete","Incomplete") 
AS Complete_Incomplete FROM Assignment_test
GROUP BY Assignment_test.Assignment, Assignment_test.BillGroup, Assignment_test.BillGroupID, Assignment_test.CountOfPlanNumber,
Assignment_test.InvComplete;

Not that what I posted is exact, or will provide the desired results. When you build a Totals query, you often get more similar records than what you want, so the Union query might be a better option. I only wanted to point out why I thought the query wouldn't work, and that it seems to me the error was not a "syntax" error.
 
Last edited:
Upvote 0
A syntax error is a very specific type of error. Is that the exact error, or is it about not having a field as part of an aggregate function?
You are trying to use an aggregate function (SUM) as a calculated field, but don't have any type of Totals query key words. I would expect this should look more like
Code:
SELECT Assignment_test.Assignment, Assignment_test.BillGroup, Assignment_test.BillGroupID, Assignment_test.CountOfPlanNumber,
Assignment_test.InvComplete, IIf(Sum([Assignment_test]![CountOfPlanNumber]+[Assignment_test]![InvComplete])=0,"Complete","Incomplete") 
AS Complete_Incomplete FROM Assignment_test
GROUP BY Assignment_test.Assignment, Assignment_test.BillGroup, Assignment_test.BillGroupID, Assignment_test.CountOfPlanNumber,
Assignment_test.InvComplete;

Not that what I posted is exact, or will provide the desired results. When you build a Totals query, you often get more similar records than what you want, so the Union query might be a better option. I only wanted to point out why I thought the query wouldn't work, and that it seems to me the error was not a "syntax" error.

That worked perfectly...Thanks so much for your support....OK
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top