Results 1 to 6 of 6
  1. #1
    jayw0e is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    3

    Selecting Relative Months in MS Access Query

    Hi, I have a table containing ledger records upon which I wish to build a query. One of the fields in this table contains dates. I would like my query to select records from the table where the date falls within eitther the previous month, the current month, or next month. So, posting this in December, my query would bring back all records where the date value was between 01/11/2015 and 31/01/2016. And when the same query runs next month (January), it will return records between 01/12/2015 and 29/02/2016.

    Probably a really easy one, just not something I've done before in MSAccess. Any help gratefully received.

  2. #2
    jayw0e is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    3
    Sorry, I should specify that I am using UK date format in my example, ie dd/mm/yyyy

  3. #3
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Give this a try?

    Code:
    Between dateadd("m",-1,dateserial(year(now()),month(now()),1) and dateadd("m",2,dateserial(year(now()),month(now()),1)-1
    Cheers,

    Jeff

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  5. #5
    jayw0e is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    3
    Thank Jeff, made a minor amendment thus: Between DateAdd("m",-1,DateSerial(Year(Now()),Month(Now()),1)) And DateAdd("m",2,DateSerial(Year(Now()),Month(Now()), 1))-1

  6. #6
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Good catch, sorry for the freehand/unverified code. Cheers!

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

Similar Threads

  1. Relative Novice - Access Tracking
    By ArmandKruger in forum Database Design
    Replies: 3
    Last Post: 05-29-2015, 08:02 AM
  2. Replies: 0
    Last Post: 06-19-2014, 05:06 PM
  3. Selecting Min and Max in query - Access 2010
    By Krazy Kasper in forum Queries
    Replies: 2
    Last Post: 10-25-2013, 11:40 AM
  4. Query to lookup relative field from table selection
    By shabbaranks in forum Queries
    Replies: 5
    Last Post: 12-20-2011, 11:12 AM
  5. Access 2007 Attachments - Relative reference
    By soringc in forum Programming
    Replies: 0
    Last Post: 11-22-2007, 10:47 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