Results 1 to 4 of 4
  1. #1
    pruuf is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    2

    Trouble Using the DBSUM function

    Hello,



    I am having trouble using the DB sum function.

    Technically, I am trying to get a running sum of a customer payments (pmts) over a 46 month span; however, I am not necessarily concerned about the exact date. I am just concerned about the month of payment.

    I have a table "TestOrderedCF" that has a list of payments, Customer ID number and Month of Payment (0-45). I have created a calculated Field called CFRef which is the Customer Number + (Month of Payment/(46)). I am envisioning creating a function that sums all the payments between the Customer ID number and the CF Ref number to get a running total. I have a field in the current query called [cfr] which is the reference for the customer month I of the row.

    When I do this:

    PMTrunningtotal: DSum("Monthpmt","TestOrderedCF","CFref<="& [cfr] )


    I can get a running total of all the payments if I have it in ascending order; however it doesn't restart at each new customer.

    PMTrunningtotal: DSum("Monthpmt","TestOrderedCF","CFref<="& [cfr] AND "CFref>="&[CustomerNumber])

    When I do this, it just sums all the month payments (All customers).

    Can someone please let me know where my syntax/logic is wrong? It is driving me nuts. Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Try

    PMTrunningtotal: DSum("Monthpmt","TestOrderedCF","CFref<=" & [cfr] & " AND CFref>=" & [CustomerNumber])

    Though you're using the same field in both tests, unless I'm blind.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pruuf is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    2
    THANK YOU!!!! That worked perfectly.

    So how am I supposed to think about this? My problem before looked like ACCESS was reading the two statements as separate conditionals. Where is Access reading the break in the two conditionals? Is the AND always inside the next pair of parenthesis?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help! Yes, the AND is always inside parentheses. Basically you're concatenating fixed text with variable things like the values from the query. Fixed text is things like the field names and operators (>, <, =, AND, OR, etc). Variable values could be values from the query as you have, form references, etc. Everything but the variable item goes inside the quotes, the variable items outside. The & connects the 2.

    Clear as mud now?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Crosstab trouble with count function
    By fret hack in forum Queries
    Replies: 1
    Last Post: 03-07-2019, 11:48 AM
  2. Having Trouble With Undo Function
    By nick404 in forum Programming
    Replies: 5
    Last Post: 06-25-2015, 02:27 PM
  3. Trouble with string variable in custom vba function
    By CurrentUser in forum Programming
    Replies: 4
    Last Post: 01-10-2014, 09:13 PM
  4. Replies: 13
    Last Post: 11-02-2012, 01:19 AM
  5. Having Trouble Returning Array from Function
    By NigelS in forum Programming
    Replies: 8
    Last Post: 08-15-2011, 07:12 AM

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