Function Code_Fragment_7_21()

Dim dbs As Database
Dim Part_A, Part_B, Part_C As String

Dim rst As Recordset

Set dbs = CurrentDb()


Part_A = "INSERT INTO INCUMBENTS ( SSN, PCN, START_DATE, END_DATE ) " _
       & "SELECT " & Chr(34) & "111223333" & Chr(34) & ", INCUMBENTS.PCN, DATE(), INCUMBENTS.END_DATE " _
       & "FROM INCUMBENTS, POSITIONS, JOB_TITLES " _
       & "WHERE SSN = " & Chr(34) & "111223333" & Chr(34) & " " _
       & "AND INCUMBENTS.START_DATE <= DATE() " _
       & "AND INCUMBENTS.END_DATE > DATE() " _
       & "AND POSITIONS.JOB_TITLE_CODE1 = JOB_TITLE_CODE " _
       & "AND JOB_TITLE = " & Chr(34) & "Director, Computer Center" & Chr(34) & " " _
       & "AND POSITIONS.START_DATE <= DATE() " _
       & "AND DATE() < POSITIONS.END_DATE;"

Part_B = "UPDATE INCUMBENTS " _
       & "SET END_DATE = DATE() " _
       & "WHERE SSN = " & Chr(34) & "111223333" & Chr(34) & " " _
       & "AND PCN <> (SELECT PCN " _
       & "            FROM POSITIONS, JOB_TITLES " _
       & "            WHERE POSITIONS.JOB_TITLE_CODE1 = JOB_TITLE_CODE " _
       & "              AND JOB_TITLE = " & Chr(34) & "Director, Computer Center" & Chr(34) & " " _
       & "              AND POSITIONS.START_DATE <= DATE() " _
       & "              AND DATE() < POSITIONS.END_DATE) " _
       & "AND INCUMBENTS.START_DATE < DATE() " _
       & "AND INCUMBENTS.END_DATE > DATE();"

Set rst = dbs.OpenRecordset(" SELECT PCN " _
                          & " FROM POSITIONS, JOB_TITLES " _
                          & " WHERE POSITIONS.JOB_TITLE_CODE1 = JOB_TITLE_CODE " _
                          & "   AND JOB_TITLE = " & Chr(34) & "Director, Computer Center" & Chr(34) & " " _
                          & "   AND POSITIONS.START_DATE <= DATE() " _
                          & "   AND DATE() < POSITIONS.END_DATE ")

rst.MoveFirst

Part_C = "UPDATE INCUMBENTS " _
       & "SET PCN = " & rst!pcn & " " _
       & "WHERE SSN = " & Chr(34) & "111223333" & Chr(34) & " " _
       & "AND START_DATE >= DATE();"
       

dbs.Execute (Part_A)
dbs.Execute (Part_B)
dbs.Execute (Part_C)

End Function

