Function Code_Fragment_5_15()

Dim dbs As Database, rst As Recordset
Dim Record_Number As Long

Set dbs = CurrentDb


'Here is the query for the assertion. Basically, we are looking for
'the query to be empty
Set rst = dbs.OpenRecordset("SELECT * " _
                          & "FROM POSITIONS AS P, POSITIONS AS P2 " _
                          & "WHERE P.END_DATE < P2.START_DATE " _
                          & "AND P.PCN = P2.PCN " _
                          & "AND NOT EXISTS ( SELECT * " _
                          & "FROM POSITIONS AS P3 " _
                          & "WHERE P3.PCN = P.PCN " _
                          & "AND (( P3.START_DATE <= P.END_DATE) " _
                          & "AND (P.END_DATE < P3.END_DATE)) " _
                          & "OR ((P3.START_DATE <= P2.START_DATE) " _
                          & "AND (P2.START_DATE < P3.END_DATE )) ) ")
                          
' If the result of the query is empty then the transaction is valid
' In Access, you can check if the result of a query is empty by checking
' the EOF and BOF properties of the output recordset

If rst.EOF And rst.BOF Then
    MsgBox ("Insertion completed")
Else
    MsgBox ("You entered an invalid input")
End If

End Function
