Solved

Date Criteria in Access Query

Posted on 2016-07-25
3
48 Views
Last Modified: 2016-07-25
I need to set a date criteria in my query but not sure how to set it up. I need it to be between the current date and the same date last year so it captures a rolling year date range. Any ideas on how I would set this up as the criteria?
0
Comment
Question by:Lawrence Salvucci
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41727577
Hi,

pls try

Between DateAdd("yyyy",-1,Date()) + 1 And Date())

Regards
1
 
LVL 1

Author Closing Comment

by:Lawrence Salvucci
ID: 41727582
Perfect! Thank you very much!
0
 
LVL 14

Expert Comment

by:wsh2
ID: 41727591
Dim strSQL as String
strSQL = _
    "SELECT * " & _
    "  FROM [MyTable] " & _
    " WHERE [MyTable].[MyDate] >= #12/31/2014# " & _
    "   AND [MyTable].[MyDate] <= #04/22/2015# "

Open in new window


OR

Dim dte1st as Date: dte1st = #12/31/2014#
Dim dte2nd as Date: dte2nd = #04/22/2015#
Dim strSQL as String
strSQL = _
    "SELECT * " & _
    "  FROM [MyTable] " & _
    " WHERE [MyTable].[MyDate] >= #" & dte1st & "# " & _
    "   AND [MyTable].[MyDate] <=  #" & dte2nd & "# "

Open in new window

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

856 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