Results 1 to 4 of 4
  1. #1
    rhofland is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Dec 2015
    Posts
    2

    Date query!!

    Hi everyone! I have what SHOULD be a simple query, but I've never really worked with Access before, so I'm having problems troubleshooting my query. I have a spreadsheet that has bill #'s in column A, a Debtor's name in column B, a Date of appointment in Column C Balance in Column D, and a billed amount in column E.



    I need to generate a report with the bill #'s, Debtor's name, and balance which eliminates data when the debtor has an appointment within the last 2 years. We can clear out those remaining claims as long as the debtor doesn't have any recent (2 years) appointments but does have bills after that date range. We can do this by exporting the remaining bills to a spreadsheet and as long as we have the debtor's name, balance and Bill #. The debtor can have many bill #'s, so I can't just simply eliminate duplicates, which is why I turned to Access to try to address this issue! There is only one table since I put it all on one spreadsheet. Below is a paste of the spreadsheet data to give a visual: See how Doe #1 has an appointment in 09 AND an appointment in 15? We do NOT want any of his bills exported to our query results; but the other ones who don't have a recent appointment, we DO want exported! Thanks in advance...I've been working on this for a week...and nobody at my work knows what the heck they are doing in Access

    Bill No: Debtor Preprd Date Balance Billed Amt
    Bill # 1 Doe,John1 30-Nov-09 30 35.58
    Bill # 2 Doe,John2 1-Dec-09 30 35.58
    Bill # 3 Doe,John1 16-Jul-15 30 35.58
    Bill # 4 Doe,John4 3-Dec-09 30 35.58
    Bill # 5 Doe,John5 4-Dec-09 30 35.58
    Bill # 6 Doe,John6 5-Dec-09 30 35.58
    Bill # 7 Doe,John7 6-Dec-09 30 35.58
    Bill # 8 Doe,John8 7-Dec-09 30 35.58
    Bill # 9 Doe,John9 8-Dec-09 30 35.58
    Bill # 10 Doe,John10 9-Dec-09 30 35.58
    Bill # 11 Doe,John11 10-Dec-09 30 35.58

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do you want to retrieve records for debtors whose LAST appointment was over two years ago? This can get tricky.

    1. build an aggregate query that pulls that latest date for each debtor - use Max() function

    2. build another query that joins first query to the data table

    3. set filter criteria on the Max date field
    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.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    a number of ways to do this - depending on how much data, the first should be the fastest

    Code:
    SELECT myTable.* 
    FROM myTable LEFT JOIN (SELECT Debtor, Max(PreDate) FROM myTable WHERE PreDate>dateadd("yyyy",-2,Date()) GROUP BY Debtor) AS Exclude ON myTable.Debtor=Exclude.Debtor
    WHERE Exclude.Debtor is null
    Code:
    SELECT * 
    FROM myTable
    WHERE Not Exists(SELECT * FROM myTable WHERE PreDate>dateadd("yyyy",-2,Date()) AND Debtor=myTable.Debtor)
    Code:
    SELECT * 
    FROM myTable
    WHERE (SELECT count(*) FROM myTable WHERE PreDate>dateadd("yyyy",-2,Date()) AND Debtor=myTable.Debtor)=0

  4. #4
    rhofland is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Dec 2015
    Posts
    2
    I need to filter out any bill for a debtor with an appointment within the last 2 years. I'll try out these suggestions tomorrow when I get back at work.

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

Similar Threads

  1. Replies: 3
    Last Post: 12-02-2014, 07:58 PM
  2. Date Query: Annual Data Based off of Form Date
    By steveabni in forum Queries
    Replies: 4
    Last Post: 04-21-2014, 02:15 PM
  3. Replies: 3
    Last Post: 03-11-2014, 07:32 PM
  4. Replies: 5
    Last Post: 12-12-2013, 12:14 PM
  5. Replies: 3
    Last Post: 08-21-2012, 03:05 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