If jmeqty is zero or null, you have a division-by-zero error in your
Variance field. That's probably the cause of the Overflow error.
Handle the zero-divisor as a special case, and use Nz() after the division:
CDbl(Nz(IIf([jmeqty]=0, 0, [jmrqty] / [jmeqty]), 0)) AS Variance
Personally, I don't trust Access to get Nz() right without specifying the
2nd argument (as above.)
That applys to the previous field as well, but you can just reverse the
logic so the null is handled by the Else case, i.e. the 3rd argument of
IIf():
IIf([jmpart] Like "PA*", IIf([jmrqty] <> 0, 0,1 ) AS Qualifier
Since these fields are part of the GROUP BY clause, they could be handled in
either the WHERE or HAVING clauses. You might like to see if it is more
efficient if you choose Where instead of Group By on these fields.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
McGrinch said:
Below is the SQL. The field in question is called "variance". When the
query runs, the result of that field aligns to the right.
SELECT [Jobs Prod Compl not issued-get compl date].MaxOfJLDATE,
[Jobs Prod Compl not issued-get compl date].[Prod Compl],
Now()-[maxofjldate] AS [Days since compl],
[Jobs Prod Compl not issued-get compl date].Job,
[Jobs Prod Compl not issued-get compl date].Level,
dbo_JJMTL.JMPART AS Part,
dbo_JJMTL.JMDESC AS [Desc],
dbo_JJMTL.JMEXTD AS [Ext Desc],
dbo_JJMTL.JMRCMP AS [Job Recd Compl],
dbo_JJMTL.JMEQTY AS [Est Qty],
dbo_JJMTL.JMRQTY AS [Issued Qty],
[jmeqty]-[jmrqty] AS [Under Issued],
IIf([jmpart] Like "PA*", IIf(nz([jmrqty])=0,1,0), 1) AS Qualifier,
CDbl(nz([jmrqty],0))/(nz([jmeqty],0)) AS Variance
FROM [Jobs Prod Compl not issued-get compl date] LEFT JOIN dbo_JJMTL
ON ([Jobs Prod Compl not issued-get compl date].Level = dbo_JJMTL.JMLEVL)
AND ([Jobs Prod Compl not issued-get compl date].Job = dbo_JJMTL.JMJOB)
GROUP BY [Jobs Prod Compl not issued-get compl date].MaxOfJLDATE,
[Jobs Prod Compl not issued-get compl date].[Prod Compl],
Now()-[maxofjldate],
[Jobs Prod Compl not issued-get compl date].Job,
[Jobs Prod Compl not issued-get compl date].Level,
dbo_JJMTL.JMPART,
dbo_JJMTL.JMDESC,
dbo_JJMTL.JMEXTD,
dbo_JJMTL.JMRCMP,
dbo_JJMTL.JMEQTY,
dbo_JJMTL.JMRQTY,
[jmeqty]-[jmrqty],
IIf([jmpart] Like "PA*", IIf(nz([jmrqty])=0,1,0), 1),
CDbl(nz([jmrqty],0))/(nz([jmeqty],0))
HAVING (((Now()-[maxofjldate])>4)
AND (([jmeqty]-[jmrqty])>0)
AND ((IIf([jmpart] Like "PA*",IIf(nz([jmrqty])=0,1,0),1))=1)
AND ((CDbl(nz([jmrqty],0))/(nz([jmeqty],0)))<0.75))
ORDER BY Now()-[maxofjldate] DESC;
ORDER BY Now()-[maxofjldate] DESC;