Results 1 to 9 of 9
  1. #1
    mbenton's Avatar
    mbenton is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    73

    Creating a query that pulls data witin 90 day's from the current date.

    Hi, I have created a simple query with a date field and other information. I only need the query to pull from the data in a 90 day window continually. In other words data dated older than 90 days is no longer relevant. I specified in my criteria the following: Between Date() and DateAdd("M",-3,Date()). I thought this would pull the data from 3 months back but it's not pulling any data. Is the criteria incorrect? Thanks.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Show the entire query SQL.
    Do you want 90 days or 3 months?
    What exactly do you want this data for?

  3. #3
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Date-90 should work. However, if your fields contain time values, using Between with dates (and no time) poses a special problem. If the field values were
    07/01/2016 2:00:00 PM and 07/13/2016 5:00:00 AM, then for
    Between #07/01/2016# And #07/13/2016#, you will get no values for 07/13/2016 because no time was specified. The second date cutoff time will be 00:00:00 (midnight).
    >= and <= operators or adding a suitable hour to the end date (DateAdd) is required.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    glitch caused me to double post (all original text disappeared when trying to edit)
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    mbenton's Avatar
    mbenton is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    73
    To give background: We have three shifts of workers. Often 2 or more people who work different shifts may work on the same account. I've been asked to create a Comments Log that will flag accounts and append them to a table where comments could be written if necessary. We only need the comments log to cover a 90 day moving window of time. The date field that I am using in my query does not have time format bound to it. This is my complete SQL statement for the query:


    SELECT Format([DateEntered],"mm-dd-yyyy") AS [Log Date], AppendLogtbl.OrderNo, AppendLogtbl.RequestorName, AppendLogtbl.ExpediteWorker, AppendLogtbl.ExpediteReason, AppendCommentstbl.[Issue/Problem], AppendCommentstbl.InitialActionTaken, AppendCommentstbl.ResponseFollowup, AppendCommentstbl.Completed, Format([UserCreated],"mm-dd-yyyy") AS [User Created]
    FROM AppendLogtbl INNER JOIN AppendCommentstbl ON AppendLogtbl.NotesID = AppendCommentstbl.NotesID
    WHERE (((Format([DateEntered],"mm-dd-yyyy")) Between Date() And DateAdd("m",-3,Date())));

    When I ran the above query I got nothing back although I'm certain that I have a few comments appended that would fall into the range.

  6. #6
    mbenton's Avatar
    mbenton is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    73
    I realize that the source table for the query does have the date and time format: "6/6/2016 1:00:00 PM" but I convert the format in my query.

  7. #7
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I would either
    - remove the criteria and see if you get any results. If not, suspect the join relationship, or your use of the format and date functions vs system settings (although I don't see what happened to your use of the DateValue function.
    - test the join by building the query in stages - start a new query with one table and add components when the results of the query look as expected
    - zip and post a db copy here, since reading your sql doesn't do much for me. There are too many factors that can't be seen without being able to look at the tables and joins.

  8. #8
    mbenton's Avatar
    mbenton is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    73
    Thanks, I'm almost certain that it's the date/time format in the source table that's causing my query not to work. Unfortunately I can't change the table format due to company restrictions, however, I can add a second date field (without the time) and base my query criteria off that date. I'll post my results, thanks everyone for your help.

  9. #9
    mbenton's Avatar
    mbenton is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2015
    Posts
    73
    It worked when I added the second date field. This is odd to me, I'm not sure why it wouldn't accept the converted date field from my query, yet when I added a new date field with the same format it worked! I guess Access doesn't like to query off converted date fields. ~~ **thanks.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-10-2016, 11:51 AM
  2. Creating a Form that pulls up data
    By Accu-Grind in forum Forms
    Replies: 6
    Last Post: 04-09-2015, 10:21 AM
  3. Replies: 2
    Last Post: 12-04-2013, 03:58 PM
  4. Creating a search Field that pulls up a record
    By RapidRepairArnold in forum Access
    Replies: 3
    Last Post: 10-17-2012, 04:33 PM
  5. Replies: 10
    Last Post: 08-21-2012, 07:16 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