Solved

Query criteria to get previous month's data not working

Posted on 2016-11-01
3
63 Views
Last Modified: 2016-11-01
I have a date field in a table and would like to enter query criteria to display the previous month's data, but every date function I've tried yields no results, even though there definitely are records from the previous month.  I suspect there's something wrong with the way the date is stored but don't know how to pin it down and resolve it.

The date is stored as a short date and is formatted to display as mm/dd/yy.    Query criteria along the lines of:  =DateAdd("m", -1, Date()), or  =Month(Date()-1), or =Month((Now)-1)), and various permutations of DateSerial yields no records.  I tried making a query with just the date field so I could try different date functions on it, but no luck.

Thanks in advance for any suggestions.
0
Comment
Question by:Cindy Aitken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41868627
You would use as criteria:

    Between DateSerial(Year(Date()), Month(Date())-1,1) And DateSerial(Year(Date()), Month(Date()),0)

/gustav
0
 

Author Closing Comment

by:Cindy Aitken
ID: 41868662
Thanks, Gustav!  That works!  Wouldn't you know, five minutes after I posted my question, I found another solution:  Year([AsnmDate])*12+DatePart("m",[AsnmDate])=Year(Date())*12+DatePart("m",Date())-1.  This statement and yours both solve the problem.  I wonder why the simpler DateAdd or Month statements wouldn't work, but I'm glad to have a solution.
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 41868713
You are welcome!

And believe me ... there are so many clumsy "solutions" out there.

/gustav
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question