Results 1 to 3 of 3
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    Query to return the record with the date immediately previous to chosen date

    I have a Table with Date; Person; Manager; Quota
    A person will/may have several records.
    For Example on
    1/1/2010 Joe has manager Paul and quota 50
    1/1/2017 Joe has manager Sam and quota 100
    4/1/2017 Joe has manager Jim and quota 500

    I open my Query for February 2017 - I want it to return Joe has manager Sam and quota 100
    But if I open Query for April 2017 - I want it to return Joe has manager Jim and quota 500
    if I open Query for December 2016 - I want it to return Joe has manager Paul and quota 50




    So I want to return / compare against historical information Choose Month(1-12) Choose Year - return the record from the date closest to but not past (like the Price is Right)

    What is the filter for Date?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    set the limit on the data given on the form, then return the max date :Q2

    Q1 :select ID, Max([Date]) from table where [date]< forms!myForm!txtDate
    Q2: select * from table where Q1.ID = Q2.ID

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,368
    maybe
    SELECT TOP 1
    SomeDate, Person, Manager, Quota FROM tblMyTable
    WHERE SomeDate < Date
    ORDER BY SomeDate DESC;

    Date is a reserved word and should not be used for any db object or field. I don't know what you'd get if you wrap your field name in square brackets [Date] but I'm pretty sure Access will return nothing if comparing WHERE Date < Date since both should return today's date given that Date is a function.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 35
    Last Post: 08-05-2016, 02:44 PM
  2. Replies: 3
    Last Post: 05-10-2016, 11:51 AM
  3. Replies: 1
    Last Post: 04-29-2016, 04:03 AM
  4. Replies: 3
    Last Post: 03-02-2016, 09:39 AM
  5. Replies: 1
    Last Post: 02-12-2013, 03:48 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