Solved

Dsum problem

Posted on 2000-04-27
8
603 Views
Last Modified: 2012-06-27
I'm creating a membership database and have problem about Dsum function. Well, i'm in the client form, but wanna know how much each client's paid so far. When i looked at the Sample Db from MSAccess ( Named Membership), i can use Dsum to get the sum from another table. This is the code from the sample
"=IIf(IsNull([MemberID]),0,DSum("[PaymentAmount]","Payments","[MemberID]=" & [MemberID]))"

So, i copied the code and paste it to my form, and changed from the [MemberID] to be [CaseID]. I also have "Payment" table, and "paymentAmount" field, The relationship is one to many. Unfortunately, i got the #error. Do u have any idea?

 
0
Comment
Question by:TerryOh
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 6

Expert Comment

by:bknouse
ID: 2755831
Try changing the name attribute of the control on the form (you find this in the properties OTHER tab).  If you originally had this named, Access gets confused and displays the #error instead of the value.

Brent
0
 
LVL 1

Expert Comment

by:JCE
ID: 2755851
If MemberId is a integer then I think your code should be like this.
=IIf(IsNull([MemberID]),0,DSum("[PaymentAmount]","Payments","[MemberID]=" & [MemberID] & ""))

If MemberId is text then it should be like this.
=IIf(IsNull([MemberID]),0,DSum("[PaymentAmount]","Payments","[MemberID]='" & [MemberID] & "'"))
Good luck
JCE
0
 

Author Comment

by:TerryOh
ID: 2756091
JCE, My MemberID is Texe, but when I tried the code that u told me, i got Blank field instead of #error. Why?
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 10

Expert Comment

by:paasky
ID: 2756399
Hello TerryOh,

You should add quotes or double quotes to criteria if you're comparing string (text) type fields:

=IIf(IsNull([MemberID]),0,DSum("[PaymentAmount]","Payments","[MemberID]='" & [MemberID] & "'"))

or

=IIf(IsNull([MemberID]),0,DSum("[PaymentAmount]","Payments","[MemberID]=" & Chr(34) & [MemberID] & Chr(34)))

chr(34) = "

Hope this helps,
Paasky

0
 
LVL 1

Accepted Solution

by:
JCE earned 20 total points
ID: 2756414
Try this first
=DSum("[PaymentAmount]","Payments","[MemberID]='" & [MemberID] & "'")
and next
=DSum("[PaymentAmount]","Payments","[MemberID]='abc'")
abc is your MemberID.
Let me know if it works.
JCE

0
 
LVL 10

Expert Comment

by:paasky
ID: 2756418
Oh oh! Sorry JCE, my intention was not to step on your toes.

Paasky
0
 
LVL 10

Expert Comment

by:paasky
ID: 2756467
Hmm.. I think the Iif is not necessary needed here, try this instead:

=DSum("[PaymentAmount]","Payments","[MemberID]='" & NZ([MemberID],"####") & "'")

Paasky



0
 

Author Comment

by:TerryOh
ID: 2756927
Hey, JCE, it works!!!!!

Thank you!!

JCE, paasky, and bknouse
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question