Function MakeSched()
Dim db As DAO.Database
Dim rstHP As DAO.Recordset
Dim rstLP As DAO.Recordset
Dim rstHPOD As DAO.Recordset
Dim rstLPOD As DAO.Recordset
Dim rstLM As DAO.Recordset
Dim strLPOD As String
Dim strMonth As String
Dim strHP As String
Dim strHPOD As String
Dim strLP As String
Dim strLM As String
strHP = "SELECT [Work Instructions].*, tblWIUnion.* FROM [Work Instructions] INNER JOIN tblWIUnion ON [Work Instructions].ID = tblWIUnion.fldWIID " & _
"WHERE ((([Work Instructions].PA)='High')) OR (((tblWIUnion.varPriChange)=True))"
strHPOD = "SELECT [Work Instructions].*, tblWIUnion.* FROM [Work Instructions] INNER JOIN tblWIUnion ON [Work Instructions].ID = tblWIUnion.fldWIID " & _
"WHERE ((([Work Instructions].PA)='High') AND (([Work Instructions].LastAudit)<=Date()-365)) OR (((tblWIUnion.varPriChange)=True))"
strLPOD = "SELECT [Work Instructions].*, tblWIUnion.* FROM [Work Instructions] INNER JOIN tblWIUnion ON [Work Instructions].ID = tblWIUnion.fldWIID " & _
"WHERE ((([Work Instructions].PA)='Low') AND (([Work Instructions].LastAudit)<=Date()-365)) OR (((tblWIUnion.varPriChange)=False))"
strLP = "SELECT [Work Instructions].*, tblWIUnion.* FROM [Work Instructions] INNER JOIN tblWIUnion ON [Work Instructions].ID = tblWIUnion.fldWIID " & _
"WHERE ((([Work Instructions].PA)='Low')) AND (((tblWIUnion.varPriChange)=False))"
strMonth = "SELECT tblMonth.ID, fldmonth From tblMonth WHERE (((tblMonth.fldActive)=True))"
strLM = "SELECT * FROM tblWIUnion"
Set db = CurrentDb
Set rstHP = db.OpenRecordset(strHP, dbOpenDynaset)
Set rstLP = db.OpenRecordset(strLP, dbOpenDynaset)
Set rstMonth = db.OpenRecordset(strMonth, dbOpenDynaset)
Set rstLM = db.OpenRecordset(strLM, dbOpenDynaset)
Set rstHPOD = db.OpenRecordset(strHPOD, dbOpenDynaset)
Set rstLPOD = db.OpenRecordset(strLPOD, dbOpenDynaset)
Do While Not rstHPOD.EOF
rstHPOD.Edit
nxtInspection = rstHPOD!fldIQADue
Do Until DCount("fldIQA", "tblWIUnion", "Format$(fldIQADue,'yyyymm')='" & Format$(nxtInspection, "yyyymm") & "'") < 3
nxtInspection = DateAdd("m", -1, nxtInspection)
Loop
rstHPOD!fldIQA = nxtInspection
rstHPOD.Update
rstHPOD.MoveNext
rstHPOD.Close
Loop
Set rstHPOD = Nothing
Do While Not rstLP.EOF
rstLP.Edit
nxtInspection = rstLP!fldIQADue
Do Until DCount("fldIQA", "tblWIUnion", "Format$(fldIQADue,'yyyymm')='" & Format$(nxtInspection, "yyyymm") & "'") < 3
nxtInspection = DateAdd("m", -1, nxtInspection)
Loop
rstLP!fldIQA = nxtInspection
rstLP.Update
rstLP.MoveNext
rstLP.Close
Loop
Set rstLP = Nothing
DoCmd.Requery
'ErrorHandler:
'MsgBox "Error #: " & Err.Number & Err.Description
End Function