I have a form where I enter activities for different students. Those activities cannot overlap.
I am trying to avoid overlapping time entries using the following code. I use DTPicker2 to enter TimeFrom and DTPicker3 to enter TimeTo. I am using vb6.
When I enter hours for a student from 9:00am to 12:00am on a particular day and then enter a student from 9:00am to 11:00am of the same day, the code below successfully blocks the second entry.
However, when I enter hours for a student from 9:00AM to 12:00AM on a particular day and then enter a student from 10:00AM to 11:00AM of the same day, the same code does not block the entry. What is wrong and how can I avoid the overlapping time entry?
'Check for duplicate entry-------
esql = "select count(*) from tblOrgHours where RegID = " & var4 & " And ActivityDate = '" & DTPicker1.Value & "' And ((HourTimeFrom >= '" & DTPicker2.Value & "' And HourTimeFrom <= '" & DTPicker3 & "') Or (HourTimeTo >= '" & DTPicker2.Value & "' And HourTimeTo <= '" & DTPicker3 & "'))"
rec.Open (esql), conn, adOpenDynamic, adLockOptimistic
If rec.Fields(0) > 0 Then
Duplicate = Duplicate + var3 & " " & var2 & vbCrLf
If Not rec.EOF Then rec.MoveNext