Results 1 to 9 of 9
  1. #1
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9

    Date Calculation and Totals in Query Does not return anything

    Hi Expert,



    I have Query for Calculate Remaining Money in a Account, for Report

    This Query must Return reaming money from Yesterday and show it on Header of Report,

    I wrote these Query but it doesn't returning any Result:

    ================================================== =========
    SELECT (Sum(Transaction.Deposit)-Sum(Transaction.Withdrawal)) AS Remain
    FROM [Transaction]
    WHERE (((Transaction.ReportDate)=Date()-1));
    ================================================== =========

    I think there is some problem with using Totals and Date calculation in a same Query

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    It works fine for me. Can you post a small sampling of your data?
    I assume that ReportDate is formatted as Date, and your Deposit and Withdrawal fields are formatted as a numeric option.

  3. #3
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    Yes Sure.

    ID ReportDate Customer Name Transaction Date Transaction Code Bank/Branch Transaction Type Deposit Withdrawal F/T Account
    2 9/19/2012 Adnan Ebrahimi 9/18/2012 R01
    Bank X1/1 Creadit
    9,999,999,999.00 21088722

    Withdrawal & Deposit data type are Currency

    ReportDate are Date/Time (Short Formatted)

    Click image for larger version. 

Name:	Query.jpg 
Views:	14 
Size:	36.8 KB 
ID:	9282

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Two things to check, both with regard to the ReportDate:
    1. Do you have any records with yesterday's date (meaning, confirm that there are records that should meet your criteria and be returned)?
    2. Is there a time component stored with ReportDate? If so, you will need to drop it, or else your "matching criteria" will be trying to match on that exact time.

  5. #5
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    Answer of 1 : Yes i have, i just post a sample here
    Answer of 2 : Yest Report Date is a Required and it's fill Automatically with Now() function.

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Answer of 1 : Yes i have, i just post a sample here
    The sample you posted has a ReportDate of 9/19/2012. Yesterday was 9/26/2012. Since your query only pulls back records from yesterday, the record you posted would NOT be returned.

    Answer of 2 : Yest Report Date is a Required and it's fill Automatically with Now() function.
    Here is the source of your problem. The Now() function not only returns current date, but it also returns the current time.

    Let's say you have a ReportDate of "9/26/2012 10:34 AM".
    Whenever time is not specificed, 12:00 Midnight is assumed. So Date()-1 returns "9/26/2012 12:00 AM".
    "9/26/2012 10:34 AM" does not equal "9/26/2012 12:00 AM", so it would not be returned. The only records that would be returned are those where the time component equals exactly 12:00 AM.

    Try changing your criteria to:
    Code:
    WHERE Int(Transaction.ReportDate)=Date()-1;
    The reason why this works is because dates are stored in Access and Excel as the number of days since 1/1/1900. Time components are fractional parts of days. So to remove the time from a day, we can remove the fractional part using the INT function.

  7. #7
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    Thanks i Solved it,

    Here is my mistake:

    I fill Report Date with Now() function which means it fills with Full date and time value and of course it's not match with my criteria!

  8. #8
    adnanebrahimi is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    9
    Thanks for your help

  9. #9
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is my mistake:

    I fill Report Date with Now() function which means it fills with Full date and time value and of course it's not match with my criteria!
    Yep, I alluded to the issues the time piece presents in my two prior replies.
    You will either want to fill it using Date() instead of Now(), or you will need to use criteria like I posted in my last reply.

    Glad it is working now.

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

Similar Threads

  1. Query involving a date calculation
    By bronzyroo in forum Queries
    Replies: 2
    Last Post: 02-14-2012, 11:41 PM
  2. Query to return only the row containing the highest date.
    By eric.opperman1@gmail.com in forum Queries
    Replies: 4
    Last Post: 03-22-2011, 08:42 PM
  3. Query return for date ranges.
    By Desstro in forum Queries
    Replies: 2
    Last Post: 09-14-2010, 06:44 AM
  4. I need to return a value for calculation.
    By FestoAccessBuilder in forum Access
    Replies: 1
    Last Post: 02-22-2009, 09:58 AM
  5. Replies: 4
    Last Post: 01-29-2009, 02:43 AM

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