Solved

Access 2010 SQL Query - Looking up last month's data

Posted on 2013-01-07
3
624 Views
Last Modified: 2013-01-07
Greetings Experts!

I am trying to create a query that looks up dates only from last month. You'll laugh, but here's the where clause I had and it worked:

WHERE (((DatePart("m",[Work week],0))=DatePart("m",Date(),0)-1));

UNTIL January :). I also realized that i wasn't checking the year...

I looked around online, and one answer was to use

DATEDIFF(m,[Work Week],date())=1

But that threw an invalid procedure call error.

All of the other stuff I saw was just wrong like my first attempt :)

As always, your help is greatly appreciated.

Thanks!
0
Comment
Question by:billg7
[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
3 Comments
 
LVL 26

Accepted Solution

by:
jerryb30 earned 500 total points
ID: 38753116
WHERE DateSerial(Year([work week]),Month([work week]),1)=DateAdd("m",-1,DateSerial(Year(Now()),Month(Now()),1))
0
 
LVL 1

Author Closing Comment

by:billg7
ID: 38753160
Beautifully simple. Love it! Thank you!
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38753167
use a where clause like this

where [work Week] between dateserial(Year(now()),Month(now())-1,1) and dateserial(Year(now()),Month(now()),0)


dateserial(Year(now()),Month(now())-1,1) will give you  12/1/2012

dateserial(Year(now()),Month(now()),0) will give you  12/31/2012
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

627 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