DSum with multiple criteria

R

RichardM

I have a problem using DSum in query with multiple criteria.
I have a query with following fields OrderNo and ItemGroupCode. On third
field I added following function:
PriceSum: DSum("[Price]";"OrderItems";("[ItemGroupCode]= '" & [ItemGroupCode]
& "'" And "[OrderNumber]=" & [OrderNumber]))
This should go into query OrderItems and sum up the Price for in query
specified OrderNumber (number field) and ItemGroupCode (Text field).
In some odd reason it sums sup all rows not according to criteria specified
rows. If I Dsum with one criteria it works but not with two.

Could please any tell me where is the problem.

Many Thanks
Rich
 
M

MGFoster

RichardM said:
I have a problem using DSum in query with multiple criteria.
I have a query with following fields OrderNo and ItemGroupCode. On third
field I added following function:
PriceSum: DSum("[Price]";"OrderItems";("[ItemGroupCode]= '" & [ItemGroupCode]
& "'" And "[OrderNumber]=" & [OrderNumber]))
This should go into query OrderItems and sum up the Price for in query
specified OrderNumber (number field) and ItemGroupCode (Text field).
In some odd reason it sums sup all rows not according to criteria specified
rows. If I Dsum with one criteria it works but not with two.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It is incorrectly formatted. Try this:

DSum("Price", "OrderItems", "ItemGroupCode = '" & ItemGroupCode & "' AND
OrderNumber = " & OrderNumber)

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSfAyoYechKqOuFEgEQKUrgCdERqNtCCeXpNa8JuaGEmcpj8AgKUAoOVc
sHAesemZYuLU2O+kLzk0pl13
=eh7B
-----END PGP SIGNATURE-----
 
A

Allen Browne

Try something like this:

PriceSum: DSum("[Price]", "OrderItems",
"([ItemGroupCode] = '" & [ItemGroupCode] &
"') AND "([OrderNumber] = " & Nz([OrderNumber],0) & ")")
 
R

RichardM

Thanks a lot, it worked very well.

Rich
I have a problem using DSum in query with multiple criteria.
I have a query with following fields OrderNo and ItemGroupCode. On third
[quoted text clipped - 5 lines]
In some odd reason it sums sup all rows not according to criteria specified
rows. If I Dsum with one criteria it works but not with two.

It is incorrectly formatted. Try this:

DSum("Price", "OrderItems", "ItemGroupCode = '" & ItemGroupCode & "' AND
OrderNumber = " & OrderNumber)

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top