Ron,
I am having a terrible time trying to figure out how to do this, for some
reason or another no matter how I set up my queries I will either get
duplicate records, or I can't get the results I want. If you wouldn't mind
could you help me get from my tables to what I want?
I have two separate tables/forms that the user enters in health treatment
records: 'tblPrevenativeHealthRecords' and 'tblTherapeuticHealthRecords'.
each table lists the date the animal receives the medicene (drug), the
animal's ID and a casenumber or GroupID (Multiple animals will receive the
same GroupID; CaseNumbers are given to an animal when they are sick, they
will keep the same case number until they recover, therefore a case number
may have several health records for the same animal and an animal may have
more than one case number, but a case number will never have more than one
animal).
Through my queries these tables and records are joined to another table
'tblDrugList', this table states the withdrawal time for each drug.
'tblTherapeuticHealthRecords' however has an additional option, if the drug
is given off label a box is checked and an "OffLabelWithdrawalDate" is
entered.
I would like to create a query that calculates the withdrawal date for each
time an animal is given any drug, and if the drug is given off label then I
would like it to calculate that time instead of the withdrawal time stated in
the 'tblDrugList'
First I created a union query to join together the two tables
'tblPrevenativeHealthRecords' and 'tblTherapeuticHealthRecords' This query
joins the following fields:
GroupID + CaseNumber
EarTag + EarTag
Date + Date
Product + Drug
Dosage + Dosage
AdmministrationRoute +AdministrationRoute
I then created a separate query 'qryWithdrawalDate', the goal of this query
is to calculate the date the withdrawal is over for each animal. The SQL for
this query is:
SELECT qryWithdrawalDatesUnion.GroupID, qryWithdrawalDatesUnion.eartag,
qryWithdrawalDatesUnion.Date, qryWithdrawalDatesUnion.Product,
qryWithdrawalDatesUnion.Dosage, tblDrugList.WithdrawalTime,
([qryWithdrawalDatesUnion]![Date])+([tblDrugList]![WithdrawalTime]) AS
WithdrawalExpired, tblTherapeuticIndTreatmentRecords.OffLabelWithdrawalTime,
([qryWithdrawalDatesUnion]![Date])+([OffLabelWithdrawalTime]) AS
OffLabelWithdrawalExpired
FROM (qryWithdrawalDatesUnion LEFT JOIN tblDrugList ON
qryWithdrawalDatesUnion.Product = tblDrugList.DrugName) LEFT JOIN
tblTherapeuticIndTreatmentRecords ON qryWithdrawalDatesUnion.Eartag =
tblTherapeuticIndTreatmentRecords.EarTag;
Up to here is where my problem is, so far, after this I can figure
everything out. The problem is I can't figure out how to have one table only
have 1 group and casenumber and still make the query work correctly. I tried
setting it to pull up the max date etc., but I couldn't get the queries to
work.
I did come up with something that might work, but it is against
normalization, it would create a field that would always be blank in table
'tblPrevenativeHealthRecords'. If I add "OffLabelWithdrawalTime" to the
table and then add it to the union query for each table I can treat them
differently in my next query and therefore eliminate duplicates, but as I
said, this creates a blank field in 'tblPrevenativeHealthRecords'
If you wouldn't mind helping me out with this problem that would be great.
I understand this is long and confusing, thank you so much for any help you
can offer.