Solved

Dsum problem

Posted on 2000-04-27
8
570 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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now