P
Peter Hibbs
With Access 2000 I have the following simple query.
SELECT tblDiary.StartTime, tblDiary.EndTime, DateValue([StartTime]) AS
StartDate, DateValue([EndTime]) AS EndDate, tblDiary.Notes,
tblCategories.ColorCode, tblCategories.Priority
FROM tblCategories INNER JOIN tblDiary ON tblCategories.Category =
tblDiary.Category
ORDER BY tblDiary.StartTime;
The table (tblDiary) has a list of appointments where the StartTime
and EndTime fields ALL hold valid date + time values. The StartDate
and EndDate are alias fields which return just the date part of the
start and end times.
In VBA code I have :-
Dim vDate As Date
vDate = Date
Set rst = CurrentDb.OpenRecordset("SELECT * FROM qryAppointments
WHERE StartDate <= #" & Format(vDate, "yyyy/m/d") & "# AND EndDate >=
#" & Format(vDate, "yyyy/m/d") & "#")
(All on one line).
The idea is to return all records where the date in vDate falls within
the range of the start date and end date for each record.
For example :-
StartTime EndTime
19/05/2009 09:00:00 19/05/2009 11:00:00
20/05/2009 09:00:00 22/05/2009 11:00:00
23/05/2009 09:00:00 24/05/2009 11:00:00
If vDate is set to 21/05/2009 (the actual time part is irrelevant for
this part of the code) then the recordset should return the second
record only because that record is the only one where the start date
is less than or equal to vDate AND the end date is greater than or
equal to vDate. Of course, in practice, the actual date in vDate is
determined by the user to return different records.
When this runs I get the "Data type mismatch in criteria expression."
error on this line of the code. If I change EndDate to EndTime I do
not get the error and the code works OK except, of course, the time
element is included which (probably) means that I will not get the
correct results. I also get the same error if I use DateValue(EndTime)
instead of EndDate although using DateValue(StartTime) does NOT
produce an error.
I don't understand why the EndDate (and DateValue(EndTime)) will
produce an error where StartDate does not. Anyone have any ideas on
why and how to fix it.
Peter Hibbs.
SELECT tblDiary.StartTime, tblDiary.EndTime, DateValue([StartTime]) AS
StartDate, DateValue([EndTime]) AS EndDate, tblDiary.Notes,
tblCategories.ColorCode, tblCategories.Priority
FROM tblCategories INNER JOIN tblDiary ON tblCategories.Category =
tblDiary.Category
ORDER BY tblDiary.StartTime;
The table (tblDiary) has a list of appointments where the StartTime
and EndTime fields ALL hold valid date + time values. The StartDate
and EndDate are alias fields which return just the date part of the
start and end times.
In VBA code I have :-
Dim vDate As Date
vDate = Date
Set rst = CurrentDb.OpenRecordset("SELECT * FROM qryAppointments
WHERE StartDate <= #" & Format(vDate, "yyyy/m/d") & "# AND EndDate >=
#" & Format(vDate, "yyyy/m/d") & "#")
(All on one line).
The idea is to return all records where the date in vDate falls within
the range of the start date and end date for each record.
For example :-
StartTime EndTime
19/05/2009 09:00:00 19/05/2009 11:00:00
20/05/2009 09:00:00 22/05/2009 11:00:00
23/05/2009 09:00:00 24/05/2009 11:00:00
If vDate is set to 21/05/2009 (the actual time part is irrelevant for
this part of the code) then the recordset should return the second
record only because that record is the only one where the start date
is less than or equal to vDate AND the end date is greater than or
equal to vDate. Of course, in practice, the actual date in vDate is
determined by the user to return different records.
When this runs I get the "Data type mismatch in criteria expression."
error on this line of the code. If I change EndDate to EndTime I do
not get the error and the code works OK except, of course, the time
element is included which (probably) means that I will not get the
correct results. I also get the same error if I use DateValue(EndTime)
instead of EndDate although using DateValue(StartTime) does NOT
produce an error.
I don't understand why the EndDate (and DateValue(EndTime)) will
produce an error where StartDate does not. Anyone have any ideas on
why and how to fix it.
Peter Hibbs.