I have these records on my Day Table name tblday
- M
- T
- W
- TH
- F
- S
- MW
- TTH
- WF
Let say if I have this existing schedule:
- ScheduleID = 10001
- StartTime = 8:30 AM
- EndTime = 1:00 PM
- Day = M
- Room = AVR
- Course = BSN
Then If I add this new entry
- ScheduleID = 10002
- StartTime = 9:00 AM
- EndTime = 10:00 AM
- Day = MW
- Room = AVR
- Course = BSN
This should prompt a conflict in schedule because there is already a schedule for monday, then the new entry shouldn't be added. : )
Note: MW means 'Monday' AND 'Wednesday', I used this if they have both the same schedule. Because it would become redundant if add a new schedule for monday and add another for thursday with the same day, time, room and course. Also the same as TTH and MWF I can only detect conflict if it is not a combination of both Days (e.g MTH, TF, ...) I really spend a lot of time regarding this issue. Please I really need your help : (
Heres the code:
Function RoomInUse() As Boolean<br><br>
Dim room As String<br>
Dim day As String<br>
Dim starttime As Date<br>
Dim endtime As Date<br>
Dim mond As String<br>
Set rs = New ADODB.Recordset<br>
With rs<br>
mond = "select * from tblsched where room Like '" & room & "%' and day like '" & room & "' and (starttime <= #" & starttime & "# And " & _<br>
"endtime >= #" & starttime & "#) Or (#" & starttime & "#" & _<br>
"<= starttime And endtime < #" & endtime & "#) Or (#" & _<br>
starttime & "# <= sarttime And starttime < #" & endtime & "#)) " '"<br>
.Open mond, con, 3, 3<br>
End With
If rs.RecordCount >= 1 Then
RoomInUse = True
Else
RoomInUse = False
End If
End Function
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…