If you were using a database with table functions and or cursors. You could probably do with the Coalesce function as well as Mon1,Mon2 is a complete waste of space, but access doesn’t have that either…
You have got to change that table.
For a start there is no explicit order.
Add a column Prod_Order,
type integer and make it an identity, if you’ve nothing else. and if this is a permanent table, make it the priomary key.
Rule one in database design never have a table without a key.
get rid of Mon1,Mon2 with
Select Prod_Order,[Prod Code]as Prod_Code,
Case When MON1 is not null Then MON2
else Mon1
As Amount,CWM
From [Product Codes]
Call that qryProductCodes
At that point you can find the first one
with something like
Select Prod_Code,Min(Prod_Order) as FirstInstance
Group By Prod_Code
From qryProductCodes
Call the query say qryFirstInstance
Then you join that back to qryProdcutCodes
to get each first row
e.g
Select pc.* From qryProductCodes pc, qryFirstIntance q
Where pc.Prod_Order = q.FirstInstance
Call That qFirstInstanceDetail
and then again to get the sum of all the other ones,
e.g.
Select pc.Prod_Code,Sum(PC.Amount) as amount From qryProductCodes pc, qryFirstIntance q
Where pc.Prod_Order <> q.FirstInstance
and pc.Prod_code = q.Prod_Code
Call that qryRestOfThem
Then you can join those results to get the answer
e.g.
Select d.Prod_Code,d.Amount,d.CWM From
qryFirstInstanceDetail d,
QryRestofThem r
Where d.Prod_Code = e.Prod_Code
and d.Amount <> r.Amount
Only other way would be to write a script to do it logic wise in VBA, but that’s a clueless numpty trick, or a one off power user script for analysis purposes.
Sometimes you have to have a table design that makes it difficult to do some things, because others were more important, if you don’t, don’t…
PS
Why are you making things harder for yourself by having column and table names with spaces in them?
PPs I’m not picking on you, this is classic newbie problem trying to use SQL which is effectively set based on data that can’t be described as a set.
Don’t know how much new stuff I’ve sprung on you either :p
I didn’t check any of it for dumbass errors either, the theory is sound though, if I’ve understood what you meant.