Results 1 to 4 of 4
  1. #1
    doodles is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2011
    Posts
    2

    DSum where data is from previous week only

    Hi,



    I have a table with account number, amount paid and paid date (TBL_DAILY_PAYMENTS).

    The first batch of records are dated 06/01/2011 and the latest batch is currently 25/01/2011 (daily file with anywhere from 1 record to 1000+).

    I'm trying to bring back the total paid for each account number in the last week as well as YTD in two columns of my account summary table (TBL-DASHBOARD).

    I've used the below update query for YTD and this seems to be working fine.

    DSum("[AMOUNT PAID]","TBL_DAILY_PAYMENTS","[ACCOUNT NUMBER] = '" & TBL_Dashboard![Account Number] & "' AND Year([PAID_DATE])= " & Year(Date()))

    My issue is with summing amounts paid in the last week and bringing those into the Dashboard table.

    I was under the understanding that the below would work...

    DSum("[AMOUNT PAID]","TBL_DAILY_PAYMENTS","[ACCOUNT NUMBER] = '" & TBL_Dashboard![Account Number] & "' AND [PAID_DATE]>= '" & DateAdd("d",-7,Date()) & "'")

    The idea is to run the update query every Monday and retrieve the latest YTD total as well as the total of amounts paid in the previous week.

    Could anybody please help me to fix my query as the DateAdd function is not working as I have been told it will and is bringing back exactly the same as the YTD total (YTD total has been checked and the updated records for this field are correct)???

    Please bear in mind that I am relatively new to Access and just want an update query...no VB or SQL please!
    Thanks very much!!!

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Code:
    DSum("[AMOUNT PAID]","TBL_DAILY_PAYMENTS","[ACCOUNT NUMBER] = '" & TBL_Dashboard![Account Number] & "' AND [PAID_DATE]>= '" & DateAdd("d",-7,Date()) & "'")
    Assuming that your [PAID_DATE] field is a date/time datatype then you have to enclose the dateadd() with # signs not single quotes. Single quotes are used for text fields, # signs are used for date/time fields. No delimiters are need for numeric fields such as the Year as in the other DSum() you mentioned.

    So the correct syntax is as follows

    Code:
    DSum("[AMOUNT PAID]","TBL_DAILY_PAYMENTS","[ACCOUNT NUMBER] = '" & TBL_Dashboard![Account Number] & "' AND [PAID_DATE]>= #" & DateAdd("d",-7,Date()) & "#")

  3. #3
    doodles is offline Novice
    Windows XP Access 2002
    Join Date
    Jan 2011
    Posts
    2
    Thank you so much...it is now working as required.

    Will I need to add # to the below code as well to ensure it work's correctly?

    DSum("[AMOUNT PAID]","TBL_DAILY_PAYMENTS","[ACCOUNT NUMBER] = '" & TBL_Dashboard![Account Number] & "' AND Year([PAID_DATE])= " & Year(Date()))

    Thanks so much again :0)

  4. #4
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Will I need to add # to the below code as well to ensure it work's correctly?
    No, since you are using the year() function, the function returns a numeric value which needs no delimiters.

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

Similar Threads

  1. Help with Sum and DSum
    By objNoob in forum Reports
    Replies: 5
    Last Post: 12-05-2011, 01:55 AM
  2. Importing new data from same file once a week
    By fclanton in forum Import/Export Data
    Replies: 0
    Last Post: 11-11-2010, 09:22 AM
  3. How do I use the DSum
    By Ironclaw in forum Access
    Replies: 1
    Last Post: 08-25-2010, 07:35 AM
  4. Help with dsum
    By bjsbrown in forum Reports
    Replies: 6
    Last Post: 02-06-2010, 09:33 AM
  5. Add data from previous record if blank
    By mbc321 in forum Queries
    Replies: 1
    Last Post: 08-08-2009, 05:15 PM

Tags for this Thread

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