I have a query, qryAppend30DayOld260ies that attempts to append
records to tblCorrespondence. When run, it can result in any of the
following: appending no records, appending 1 record or appending
many records. Two of the target fields in tblCorrespondence receiving
values in the append operation are [VehicleJobID] and [OutType]. For
any given VehicleJobID value, I want only ONE record in correspondence
table to have an [OutType] value of "01". This query blindly appends
to the correspondence table without regard to whether there is already
a record in tblCorrespondence having say a value of 100 in
[VehicleJobID] and "01" in [OutType]. How can I make this query "look"
at what's in correspondence table while appending to determine that no
record in correspondence table already has matching values in the
[VehicleJobID] and [OutType] fields, avoiding putting in redundant
records?
INSERT INTO tblCorrespondence ( VehicleJobID, OutType, ToWhom, UserID,
InProcessor, Tracked )
SELECT DISTINCTROW tblCorrespondence.VehicleJobID, "01" AS OutType,
tblCorrespondence.ToWhom, "System" AS UserID,
tblCorrespondence.InProcessor, True AS Tracked
FROM tblVehicleJobs INNER JOIN tblCorrespondence ON
tblVehicleJobs.VehicleJobID = tblCorrespondence.VehicleJobID
WHERE (((tblCorrespondence.InProcessor) Is Null) AND
((tblCorrespondence.OutDate) Is Not Null) AND
((tblCorrespondence.OutProcessor) Is Not Null) AND
((tblCorrespondence.OutType)="00") AND
((DateDiff("d",[DateLeft],Now()))>=30) AND
((tblVehicleJobs.Reclaimed)=No) AND
((tblVehicleJobs.ENF260Written)=True));