
Originally Posted by
hvacfixer
OK, my first post. I have three tables. (tblLocations, tblEquipment, and tblCalls). The tblEquipment table has 4 fields. (EqID, LastPMDate, PMSchedule and LocID). The tblLocations table has 2 fields. (LocID and Name). The tblCalls table has 5 fields. (CallID, DateGenerated, DateCompleted, CallType, and LocID). All tables are related by LocID.
What I am trying to accomplish is to Generate Calls based on the PM Schedule and the Last PM Date. The CallType field in the tblCalls table is used to record whether the calls are PM or Trouble. That is the only allowed values for that field. The PMSchedule field in the tblEquipment table is used to record either Quarterly or Semi-Annually. The DateGenerated and DateCompleted fields in the tblCalls table is used to record the dates that the call was generated and completed respectively.
I have been able to get the locations calls should be generated for correctly with the following query:
SELECT tblLocations.Name, tblLocations.LocID
FROM (tblLocations INNER JOIN tblCalls ON tblLocations.LocID = tblCalls.LocID) INNER JOIN tblEquipment ON tblLocations.LocID = tblEquipment.LocID
WHERE (((tblEquipment.LastPMDate)<Date()-91) AND ((tblEquipment.PMSchedule)="Quarterly")) OR (((tblEquipment.LastPMDate)<Date()-182) AND ((tblEquipment.PMSchedule)="Semi-Annually"))
GROUP BY tblLocations.Name, tblLocations.LocID
ORDER BY tblLocations.LocID;
The problem arises when all generated PM Calls have not been completed and I need to generate a new set of PM Calls. It will give me a list of locations that are duplicates of the already generated but not yet completed calls. ( The LastPMDate field in the tblEquipment is updated with the DateCompleted field value in the tblCalls table). So I need to modify my query to exclude those locations that have a PM call already generated but not yet completed.
Any help would be greatly appreciated. I am currently working around this by running my query above and having it make a temporary table, then I run another query to delete the locations where PM calls have been generated but not completed. But, I know there has to be a way to alter this query to give me the locations I need.
Sorry for the long post, I hope it is clear.