Results 1 to 8 of 8
  1. #1
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95

    Using the DSum Function for the first time

    Hello. I am new to the DSum function and could use some guidance. I have tried researching it, but am not finding the info to really help me understand why it won't work in my report.

    I tried using this function in a query and it worked just fine. But for some reason when I put it in a text box in a report the result is "#Error" or "Name?"

    My report is linked to a query - the name of this query is "production combined for report". I have a field called "Payable" that I need the values summed if the value in the "department" field is "Kitchen"

    (I have no idea how to do SQL or VBA by the way) So then this is my code:

    DSum("[payable]", "[production combined for report]", "[department]= kitchen")

    I'm not sure if I'm screwing up on the placement of the brackets and/or the quotation marks?



    Thanks in advance for the help!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "Kitchen" is a text literal. In this case, it needs to be surrounded with single quotes because it is within double quotes.

    Try
    DSum("[payable]", "[production combined for report]", "[department]= 'kitchen'")


    PS ... shouldn't use spaces in object names...

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    I don't think you need DSum. Domain aggregates can be slow performers in query or textbox. Also, your expression doesn't consider if the report has been filtered by maybe a date period or some other criteria. So unless you want a sum that doesn't synchronize with the records selected on report, use your DSum. Otherwise, since the fields are part of the report RecordSource, use Sum() with IIf() in expression in textbox placed in footer section.

    =Sum(IIf([Department]="kitchen", [payable], 0))

    Or construct the report with a Department grouping and Sum expression in group footer: =Sum([Payable])

    BTW, without the apostrophes the DSum should fail in query as well.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    Wow that was a quick fix. Thank you both for your very useful information. Your replies helped me out tremendously!

  5. #5
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    Sorry.. One more quick question: If I want to tell access to sum the values if the department is "kitchen" or "maintenance" can I do something like this:

    DSum("[payable]", "[production combined for report]", "[department]= 'kitchen' or 'maintenance'")

    That doesn't work so I'm sure I need to fix the language in there somewhere...

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Have to repeat the field name:

    "department='kitchen' Or department='maintenance'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    I wondered about that. Gosh now I feel dumb. But nonetheless, thank you!

  8. #8
    Jessica240 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    95
    Also I should mention: WOW, June! You were not kidding about the dsum function being a slow performer! Oh my goodness it is terribly slow!!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Use the Date as a criteria in Dsum function
    By Ank_db in forum Queries
    Replies: 1
    Last Post: 01-18-2015, 12:08 PM
  2. Dsum Function
    By LOIZOS in forum Forms
    Replies: 10
    Last Post: 03-20-2014, 10:05 AM
  3. DSum Function
    By azhar2006 in forum Forms
    Replies: 7
    Last Post: 12-08-2013, 05:07 PM
  4. Dsum() Function
    By rkalapura in forum Queries
    Replies: 2
    Last Post: 10-24-2012, 05:58 PM
  5. Dsum() function
    By rkalapura in forum Forms
    Replies: 3
    Last Post: 10-10-2012, 10:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums