PERHAPS the following will work for you. I note that you placed the
expression in the SELECT clause and that will return true or false in the
column. The expression should be in the WHERE clause to limit the records
returned.
SELECT tblPatients.PtLName, tblPtLocation.PtLocEnDtTm,
tblAreaList.AreaName,
tblPatients.DCDtTm, tblPatients.PtID, tblPatients.AdmitNum
, tblPtThpy.ThpyStDtTm
, tblPtThpy.ThpyEndDtTm
, Format([ThpyEndDtTm]-[ThpyStDtTm],"Fixed") AS VentLOS
, tblPatients.AdmitDtTm
, Format([DCDtTm]-[AdmitDtTm],"Fixed") AS AdmLOS
, tblTherapyType.TherapyTypeID
, tblPtLocation.PtLocStDtTm
, [ThpyStDtTm]>=[PtLocStDtTm] And [ThpyEndDtTm]<=[PtLocEnDtTm] AS Expr1
FROM (tblPatients INNER JOIN (tblAreaList INNER JOIN tblPtLocation ON
tblAreaList.AreaID=tblPtLocation.AreaID_fk) ON
tblPatients.PtID=tblPtLocation.PtID_fk) INNER JOIN (tblTherapyType INNER
JOIN tblPtThpy ON tblTherapyType.TherapyTypeID=tblPtThpy.ThpyTypeID_fk) ON
tblPatients.PtID=tblPtThpy.PtID_fk
WHERE tblAreaList.AreaName="MICU" AND
tblPtThpy.ThpyStDtTm<#10/1/2009# AND
tblTherapyType.TherapyTypeIDIn (70,97) AND
ptThdpyStDtTm>=PtLocStDtTm AND
ptThpyEndDtTm <=ptLocEndDtTm
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Linda said:
I entered it in the field row at the end of my query grid. Do you mean
put it in the criteria row under all my date fields? Here is my sql. In
the meantime I'll keep trying different things and looking in my Access
Bible.
SELECT tblPatients.PtLName, tblPtLocation.PtLocEnDtTm,
tblAreaList.AreaName, tblPatients.DCDtTm, tblPatients.PtID,
tblPatients.AdmitNum, tblPtThpy.ThpyStDtTm, tblPtThpy.ThpyEndDtTm,
Format([ThpyEndDtTm]-[ThpyStDtTm],"Fixed") AS VentLOS,
tblPatients.AdmitDtTm, Format([DCDtTm]-[AdmitDtTm],"Fixed") AS AdmLOS,
tblTherapyType.TherapyTypeID, tblPtLocation.PtLocStDtTm,
[ThpyStDtTm]>=[PtLocStDtTm] And [ThpyEndDtTm]<=[PtLocEnDtTm] AS Expr1
FROM (tblPatients INNER JOIN (tblAreaList INNER JOIN tblPtLocation ON
tblAreaList.AreaID=tblPtLocation.AreaID_fk) ON
tblPatients.PtID=tblPtLocation.PtID_fk) INNER JOIN (tblTherapyType INNER
JOIN tblPtThpy ON tblTherapyType.TherapyTypeID=tblPtThpy.ThpyTypeID_fk)
ON tblPatients.PtID=tblPtThpy.PtID_fk
WHERE (((tblAreaList.AreaName)="MICU") AND
((tblPtThpy.ThpyStDtTm)<#10/1/2009#) AND
((tblTherapyType.TherapyTypeID)=70 Or
(tblTherapyType.TherapyTypeID)=97));
My last child graduates from HS in June, I promise you all I'll take some
classes <g>
Linda
Rereading you post and noted that you entered the criteria in a NEW
criteria row. That means the criteria would return all the records
based on the first criteria row PLUS any records found in the second
criteria row.
You need the date criteria in the same row (or rows) as your existing
criteria.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Linda RQ wrote:
Hi John,
I entered that expression into my query in a new row in my query grid
and I got the same number of records as I did without the expression.
I also tried to just enter ptThdpyStDtTm>=PtLocStDtTm in and got the
same results. I do already have some criteria in this query too like
first is to only show records from a certain area (MICU) and to only
show records after a certain date. If I post the sql would that help?
I have many tables in this query so it will take a while for me to type
up my relationships etc but I'll get a start on it as that sometimes
helps me to figure out what is going on.
Thanks,
Linda
A guess.
WHERE ptThdpyStDtTm>=PtLocStDtTm AND ptThpyEndDtTm <=ptLocEndDtTm
That assumes that the four fields are in the same record. If not, you
need to tell us where the fields are and how they tables or records
are related.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Linda RQ wrote:
Using Access 2003 and I use the query grid for my criteria etc. I
have a list of patients who were on a particular therapy and a list
of all the units they were in for their entire stay. I have filtered
it down to only the patients who where in the unit I am looking at.
I need to find the patients who started on a therapy after they
arrived in a unit and who were off the therapy before they left the
unit. Many where on the therapy in other units before getting
transferred or on the therapy after they left, I don't want them in
my results. My Date units show me Date and Time in the same field.
They are named..I have been thinking maybe I need 2 more queries, one
to show the records of patients who started on therapy after they
arrived then make another query from that one for patients off the
therapy before they left but I still don't quite know how to write up
that expression.
PtLocStDtTm
PtLocEndDtTm
PtThpyStDtTm
PtThpyEndDtTm
Thanks,
Linda