473,657 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dsum Issue

28 New Member
Hello,

Thanks to a previous helper I found some great Dsum info here:

http://www.mvps.org/access/general/gen0018.htm

Unfortunately I can't get the code to work for my requirements.

I'm trying to sum the payment received ($) field within my 'tbl_treatment payments' table for every record that has the field "payment method" = cash.

The code I'm using is:

=DSum("payment received","tbl_ treatment payments","paym ent method = cash")

I'm sure my mistake is something simple, however I can't for the life of me figure it out. It's driving me crazy.

This is all for a report in Access 2000.

Thanks!
Oct 15 '07 #1
19 3373
MikeTheBike
639 Recognized Expert Contributor
Hello,

Thanks to a previous helper I found some great Dsum info here:

http://www.mvps.org/access/general/gen0018.htm

Unfortunately I can't get the code to work for my requirements.

I'm trying to sum the payment received ($) field within my 'tbl_treatment payments' table for every record that has the field "payment method" = cash.

The code I'm using is:

I'm sure my mistake is something simple, however I can't for the life of me figure it out. It's driving me crazy.

This is all for a report in Access 2000.

Thanks!
Hi

Looking at the site you references above, I suggest you look at the second line given

For numerical values:
DLookup("FieldN ame" , "TableName" , "Criteria = n")

For strings: (note the apostrophe before and after the value)
DLookup("FieldN ame" , "TableName" , "Criteria= 'string'")

For dates:
DLookup("FieldN ame" , "TableName" , "Criteria= #date#")

on the basis that 'cash' is a text field ??


MTB
Oct 15 '07 #2
dozingquinn
28 New Member
Looking at the second example, I tried the apostrophe before and after the criteria - but alas it still didn't work.

=DSum("payment received","tbl_ treatment payments","paym ent method= ‘cash’")

Payment method is a text field.
Oct 15 '07 #3
Lysander
344 Recognized Expert Contributor
Looking at the second example, I tried the apostrophe before and after the criteria - but alas it still didn't work.

=DSum("payment received","tbl_ treatment payments","paym ent method= ‘cash’")

Payment method is a text field.
You have spaces in your field names, so you need to enclose them in brackets

=dsum("[payment received]","tbl_treatmen t payments","[Payment method]='cash'")

You might have to put the table name in [ ] as well .
Oct 15 '07 #4
dozingquinn
28 New Member
Thanks for the suggestion,

I tried the brackets - (both suggestions) - but I still return a #error value.

:(
Oct 15 '07 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thanks for the suggestion,

I tried the brackets - (both suggestions) - but I still return a #error value.

:(
Try it using the nz (null to zero) function like this:
=dsum(nz("[payment received]",0),"tbl_treat ment payments","[Payment method]= 'cash'")
Oct 16 '07 #6
dozingquinn
28 New Member
Thankyou Puppy!

I now get a value! (Total cash sales across the whole record set). I see now (after reading up on NZ functions) that the 0's must have been causing issues.

As my report is grouped by month, is it possible to extend the formula so that it only dsum's the values within the given month?

Looking round I tried to decipher it myself - however my stab in the dark hasn't been fruitful:

=DSum(nz("[payment received]",0),"tbl_treat ment payments","[Payment method]= 'cash'" AND “[Payment date]” = & 'MM())
Oct 16 '07 #7
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thankyou Puppy!

I now get a value! (Total cash sales across the whole record set). I see now (after reading up on NZ functions) that the 0's must have been causing issues.

As my report is grouped by month, is it possible to extend the formula so that it only dsum's the values within the given month?

Looking round I tried to decipher it myself - however my stab in the dark hasn't been fruitful:

=DSum(nz("[payment received]",0),"tbl_treat ment payments","[Payment method]= 'cash'" AND “[Payment date]” = & 'MM())
Try this syntax, (using February as an example).
=DSum(nz("[payment received]",0),"tbl_treat ment payments","[Payment method]= 'cash'" AND Month(“[Payment date]”) = 2)

the 0's must have been causing issues
It isn't the zeros causing the issues, it is the nulls(where nothing is entered for payment). The nz function converts the nulls to zeros to resolve the issues.
Example:
null + $50 = null
0 +$50 = $50
Oct 16 '07 #8
dozingquinn
28 New Member
Thanks again.

Nearly there...

When I indicated that my report was grouped by months I should have also clarified that the report autogenerates all the months. Is it possible to tie the month criteria to the month in question - rather than hardcoding it to a specific month?

Or am I going about this the wrong way?
Oct 16 '07 #9
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thanks again.

Nearly there...

When I indicated that my report was grouped by months I should have also clarified that the report autogenerates all the months. Is it possible to tie the month criteria to the month in question - rather than hardcoding it to a specific month?

Or am I going about this the wrong way?
If you have a FiscalMonth in your table, you can do something like this:
Try this syntax, (using February as an example).
=DSum(nz("[payment received]",0),"tbl_treat ment payments","[Payment method]= 'cash'" AND Month(“[Payment date]”) = [FiscalMonth])
Oct 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3349
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression, or maybe even DCount might be an alternative. I have tried numerous combinations, but with no apparent success. The DSum function relates to a subform (sfrmCost) with a text box (RefCost) which is intended to be the container for a total from a query (qryItems). The query has three number columns from the table (tblItems) of which I have an expression...
1
3959
by: Dalan | last post by:
This seems a bit odd, but I have not been able to persuade Access 97 to format several DSum total columns in Currency - Standard format. It appears to be defaulting to a general number format instead. The text box format is set to standard and so is the related query properties supplying the totals. Does anyone have any ideas as to a workaround for this issue? Thanks, Dalan
2
11583
by: Dalan | last post by:
I seemed to be having problems with structuring the use of NZ with a DSum expression. Having tried numerous variations of the expression without success, I'm asking for assistance. First some background (Access 97) - the DSum expressions are being used in grand total text boxes on the footer of a subform. And when viewing the subform in the linked main form the two grand total boxes display #Error if no entry had been made. Those with...
0
1587
by: Dalan | last post by:
I have a select query with a few DSum expressions, but when I add a between and ending date parameter to Date Sold, the results show #Error in two (discount and net sales) of the four gross total columns. This is a sales activity query that has GT Units Sold, GT Gross Sales, GT Discount, and GT Net Sales columns. Without using the date parameter, all grand totals are computed correctly. Not that it should be an issue, I am using NZ as part...
1
1927
by: Marc Aube | last post by:
Is there a web site that can ofer some help. The quotation marks are posing an issue as well as other items for this function. I have some books but they are not consistent in their use of the code lingo. Thank you for any help. Presently I have tables and forms to gather employee info. I use the subform to gather status of absence, text field. What I want to do is calculate the vacation hours and subtract them from the total alocation of...
1
4433
by: phaddock4 | last post by:
Being fairly inexperienced at Access 2000, i've been reading many posts here for the last several days, and testing myself to find the best approach to do the following in A2K: SET UP: I have created a MainTable (and related form), which has an associated SubForm (popup) along with its underlying, separate Table. The tables' relationship is one to many respectively. The primary key
3
2986
by: technocraze | last post by:
Hi community experts, I am having an isue with Dsum function that is used to count the total number for a particular field (intake) at the textbox afterupdate event with condition/ criteria (subject). Below is the scenario in details. What I need to do is summing the intake corresponding to what is selected from the dropdown combo box. For instance if the user choose maths in the combo box, the total no of intake should be displayed in...
3
4698
patjones
by: patjones | last post by:
Good morning all: In what seems like an ongoing saga to make the DSum function do what I need it to, I am now having trouble with a user-defined function in my VBA module. Here's the offending line of code: Me!txtLostDaysNoPaySeasonal = DSum("getNumberOfWeekdays(!, !)", "qryTest", "! = 'BK21312'") In this, getNumberOfWeekdays is a function that I define elsewhere in the module, as such: Function getNumberOfWeekdays(dteStartDate...
9
5421
by: BlackJack17 | last post by:
Alright you all have been so helpful with everything else that I thought I'd run one more issue by you. I have put together a report that is driven by a query. This query (Unique Records) returns all unique records in a table (DDRS Data). Each unique record is a string of elements from the table (15 different ones total) and I'm trying to get the report to sum the multiple dollar amounts that appear for each unique record. I've used the DSum...
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.