I am needing help with some queries. I currently have a PM form that duplicates the daily records so I was wondering if someone could look at these two queries and tell me if anything in them might cause duplication.
The first is for a daily pm list:
And the second deals with weekends because we are not always open..
The first is for a daily pm list:
Code:
INSERT INTO [PM History] ( [PM#], [Last Print Dte], [Date Generated], Status, [Date Scheduled] )
SELECT [PM Master Tbl].[PM#], Now() AS Expr1, IIf(IsNull([Lst Dte Generated]) Or [# of days]=1,Now(),[Lst Dte Generated]+[# of days]) AS Expr2, "Open" AS Expr3, DateValue([Expr2]) AS Expr4
FROM ([PM Master Tbl] INNER JOIN [PMs performed] ON [PM Master Tbl].[PM#]=[PMs performed].[PM#]) INNER JOIN Frequency ON [PM Master Tbl].Frequency=Frequency.Frequency
WHERE ((([PM Master Tbl].[PM or OPM])="pm") AND (([PM Master Tbl].Active)=Yes) AND ((IIf(IsNull([lst dte generated]),"y","n"))="Y")) OR ((([PM Master Tbl].[PM or OPM])="pm") AND (([PM Master Tbl].Active)=Yes) AND ((IIf(DateDiff("d",DateValue([lst dte generated]),Now())>=[# of days],"y","n"))="Y"))
ORDER BY Frequency.[# of days];
And the second deals with weekends because we are not always open..
Code:
INSERT INTO [PM History] ( [PM#], [Last Print Dte], [Date Generated], Status, [Date Scheduled] )
SELECT [PM Master Tbl].[PM#], Now() AS Expr1, IIf(IsNull([Lst Dte Generated]),Now(),[Lst Dte Generated]+[# of days]) AS Expr2, "Open" AS Expr3, DateValue([Expr2]) AS Expr4
FROM ([PM Master Tbl] INNER JOIN [PMs performed] ON [PM Master Tbl].[PM#]=[PMs performed].[PM#]) INNER JOIN Frequency ON [PM Master Tbl].Frequency=Frequency.Frequency
WHERE (((Frequency.[# of days])>1) AND (([PM Master Tbl].[PM or OPM])="pm") AND (([PM Master Tbl].Active)=Yes) AND ((IIf(IsNull([lst dte generated]),"y","n"))="Y")) OR (((Frequency.[# of days])>1) AND (([PM Master Tbl].[PM or OPM])="pm") AND (([PM Master Tbl].Active)=Yes) AND ((IIf(DateDiff("d",DateValue([lst dte generated]),Now())>=[# of days],"y","n"))="Y"))
ORDER BY Frequency.[# of days];