Solved

Access 2003 Query return values that have

Posted on 2010-09-10
10
395 Views
Last Modified: 2013-11-28
I am trying to create a query in MS Access to display users with training dates that are going to expire within 1 week (trainings expire a year from previous training date).  I am familiar with Oracle's date function and using truncate, however I am having issues finding the equivalent in MS Access.


SELECT Employees.Last_Name, Employees.First_Name, Employees.Dept, Employees.Last_Training_Date, Employees.Notes
FROM Employees
WHERE (([Last_Training_Date]< "yyyy", -1, Date()));
0
Comment
Question by:singi007
  • 4
  • 4
  • 2
10 Comments
 
LVL 1

Expert Comment

by:NEVAEHSIN
ID: 33648540
You can try...

[Last_Training_Date]<=DateAdd("yyyy", -1, Date)
0
 

Author Comment

by:singi007
ID: 33648770
It says "Data type mismatch in criteria expression" and I think that would just get me 1 year past, I need it to give me the users that are within 1 week of a year past due.
0
 
LVL 1

Expert Comment

by:NEVAEHSIN
ID: 33648898
First off - is [Last_Training_Date] Date/Time format?

Next try....
 where DateAdd("yyyy",1,Last_Training_date)>DateAdd("d",-7,Date());
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33648905
Catches those who are both overdue, and who have a week left:


SELECT Employees.Last_Name, Employees.First_Name, Employees.Dept, Employees.Last_Training_Date, Employees.Notes
FROM Employees
WHERE DateAdd("yyyy", -1, DateAdd("d", -7, Date())) <= [Last_Training_Date])

Open in new window

0
 

Author Comment

by:singi007
ID: 33661520
Yes, Last_Training_Date is a Date/Time format. The syntax

WHERE DateAdd("yyyy", -1, DateAdd("d", -7, Date())) >= [Last_Training_Date]

gives me those that are both overdue and who have a week left, but I want to differentiate between the two. Is it possible to break it into 2 queries? or some other method of displaying the 2 different groups?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33662003
Give this a try:
SELECT Employees.Last_Name, Employees.First_Name, Employees.Dept, Employees.Last_Training_Date, Employees.Notes,
    IIf(DateAdd("yyyy", 1, [Last_Training_Date]) > Date(), "Overdue", "Expiring Soon") AS Status
FROM Employees
WHERE DateAdd("yyyy", -1, DateAdd("d", -7, Date())) <= [Last_Training_Date])

Open in new window

0
 

Author Comment

by:singi007
ID: 33664877
Ok, I think from your solution I figured out how to get and differentiate the overdue employees and the overdue in the next 7 days employees. Is there anyway to use this IIf function to differentiate between 3 sets, for example the overdue employees, employees 7 days from being overdue and 6 weeks from being overdue? or does the IIf function only allow 2?
SELECT Employees.Last_Name, Employees.First_Name, Employees.DEPT, Employees.Last_Training_Date, Employees.Notes,
IIf(DateAdd("d", 365 , [Last_Training_Date]) < Date(), "Overdue", "Expiring within 7 Days") AS Status
FROM Employees
WHERE ( DateAdd("d", -358, Date())) >= [Last_Training_Date]
order by Last_Training_Date;

Open in new window

0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 33665202
singi007,We're starting to get kind of far afield now with the follow-ups.  Your original question has been answered, and so I think it's time to close this.  One more for the road, see below.This uses the Switch function.  You could use embedded IIfs, but I prefer not to.  Please see my article on the subject:http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_3556-Using-the-Switch-Function-in-Microsoft-Access.htmlPatrick
SELECT Last_Name, First_Name, DEPT, Last_Training_Date, Notes,
Switch(DateAdd("d", 365, [Last_Training_Date]) < Date(), "Overdue", DateDiff("d", Date(), DateAdd("yyyy", 1, [Last_Training_Date])) <7, "Due within 7 days", True, "Due in 8-42 Days") AS Status
FROM Employees
WHERE DateAdd("d", 42, (DateAdd("yyyy", -1, Date()))) >= [Last_Training_Date]
order by Last_Training_Date;

Open in new window

0
 

Author Comment

by:singi007
ID: 33665319
Thank you! This is exactly what I was trying to figure out. I thought it would be easy to figure out the rest once I had the first part, but then realized it wasn't as simple as I had hoped.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33665397
singi007,Glad to help!  If you have not already done so, I would really appreciate it if you could please return to my articlehttp://www.experts-exchange.com/Microsoft/Development/MS_Access/A_3556-Using-the-Switch-Function-in-Microsoft-Access.htmland click 'Yes' for the 'Was this helpful?' voting.matthewspatrick
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

831 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