Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Summing in a Report

Experts,

I need to sum tblPayments.Amount in the below.  How can I do this?  I have tried to put the word SUM in many places.  
This is a field in a report.
I can not drag in tblPayments to the query so I need the Dlookup.  
 

=IIf([PaidInFullYN]=True,"Paid In Full",Format(Nz(DLookUp("[Amount]","tblPayments","[LCID] = " & [LetterOfCreditID]),0),"Currency"))
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

if this is a report, you might want to consider the RunningSum property of a textbox.

But instead of DLOOKUP, why don't you use DSUM("Amount", "tblPayments", "[LCID] = " & [LetterOfCreditID]).

I think you could probably get rid of the NZ in there as well.
Avatar of pdvsa

ASKER

Hi Dale,

I actually didnt need the Dlookup after using the Dsum as you state above.  I got confused on Dlookup.  

I need to add a condition to the false part.  

Currently, the Dsum sums all of the records for "Amount","tblPayments","[LCID] = " & [LetterOfCreditID])) but  I need for the Dsum to only sum for the below condition on another checkbox called PAIDYN (see bold below):

the condition:
If Dlookup PAIDYN = True then sum those records on "Amount","tblPayments","[LCID] = " & [LetterOfCreditID])
SumPayments: IIf([PaidInFullYN]=True,"Paid In Full",DSum("Amount","tblPayments","[LCID] = " & [LetterOfCreditID]))

I dont think I can use SUM in the query design window because I get an error when I change Dsum to Sum.  Also, tblPayments is not in the query and I cant drag it in because it messes up the record count so I might need to use dlookup. (i dont know).
ASKER CERTIFIED SOLUTION
Avatar of crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pdvsa

ASKER

Hi Crystal,  (typing from phone) thank you for the comment. I actually did exactly what you said and it does work. I did not add that query to the recorsource but i instead used Dsum on the report.  I ran into another problem in that access wont allow to sum this field on the report footer. Its like I solve one problem but then have another.

Do you have a work around suggestion?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial