Or this:
PARAMETERS
Forms!YourForm!YourCalendarControl DATETIME;
SELECT CMSID, DateCompleted, TimeCompleted,
DATEDIFF("n",
(SELECT MAX(TimeCompleted)
FROM tblCompletedMessages AS CM2
WHERE CM2.TimeCompleted
< CM1.TimeCompleted),
TimeCompleted) AS TimeDifference
FROM tblCompletedMessages AS CM1
WHERE DateCompleted = Forms!YourForm!YourCalendarControl;
or if you want the time difference between rows with the same CMSID value, i.
e. since the last entry by the CMSID rather than the last entry per se:
PARAMETERS
Forms!YourForm!YourCalendarControl DATETIME;
SELECT CMSID, DateCompleted, TimeCompleted,
DATEDIFF("n",
(SELECT MAX(TimeCompleted)
FROM tblCompletedMessages AS CM2
WHERE C2.CMSID = C1.CMSID
AND CM2.TimeCompleted
< CM1.TimeCompleted),
TimeCompleted) AS TimeDifference
FROM tblCompletedMessages AS CM1
WHERE DateCompleted = Forms!YourForm!YourCalendarControl;
I've assumed that you are using the Date() and Now() functions to
automatically enter the DateCompleted and TimeCompleted values, in which case
the TimeCompleted column will also include the date, even if you are
formatting it to show the time only. If on the other hand you are either
manually entering the TimeCompleted value or are 'stripping off' the date
with TimeValue(Now()) (which in fact does not remove the date element from
the value but sets it to Access's day-zero of 30 December 1899) then you'll
need to combine both values like so when computing the difference in minutes:
PARAMETERS
Forms!YourForm!YourCalendarControl DATETIME;
SELECT CMSID, DateCompleted, TimeCompleted,
DATEDIFF("n",
(SELECT MAX(DateCompleted+TimeCompleted)
FROM tblCompletedMessages AS CM2
WHERE CM2.DateCompleted+CM2.TimeCompleted
< CM1.DateCompleted+CM1.TimeCompleted),
DateCompleted+TimeCompleted) AS TimeDifference
FROM tblCompletedMessages AS CM1
WHERE DateCompleted = Forms!YourForm!YourCalendarControl;
or:
PARAMETERS
Forms!YourForm!YourCalendarControl DATETIME;
SELECT CMSID, DateCompleted, TimeCompleted,
DATEDIFF("n",
(SELECT MAX(DateCompleted+TimeCompleted)
FROM tblCompletedMessages AS CM2
WHERE C2.CMSID = C1.CMSID
AND CM2.DateCompleted+CM2.TimeCompleted
< CM1.DateCompleted+CM1.TimeCompleted),
DateCompleted+TimeCompleted) AS TimeDifference
FROM tblCompletedMessages AS CM1
WHERE DateCompleted = Forms!YourForm!YourCalendarControl;
Ken Sheridan
Stafford, England
Here it is:
SELECT tblCompletedMessages.CMSID, tblCompletedMessages.DateCompleted,
tblCompletedMessages.TimeCompleted
FROM tblCompletedMessages;
I need the WHERE condition to include the criteria of DateCompleted equals
the date selected on a calendar control on my form. CMSID is the employee ID
of the person that the entry refers to. The TimeCompleted field is what I am
trying to calculate the difference upon.
Thanks,
Steve
Post a SQL of a select query containing all the fields to use.
[quoted text clipped - 10 lines]
--
Message posted via AccessMonster.com
.