?
Solved

Access 2003 Query return values that have

Posted on 2010-09-10
10
Medium Priority
?
399 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
[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
  • 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
LVL 93

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 93

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 93

Accepted Solution

by:
Patrick Matthews earned 500 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 93

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

752 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