Detecting Conflict in Day vb 6.0 and ms access

▼魔方 西西 提交于 2019-12-25 01:36:51

问题


I have these records on my Day Table name tblday

  1. M
  2. T
  3. W
  4. TH
  5. F
  6. S
  7. MW
  8. TTH
  9. 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

来源:https://stackoverflow.com/questions/28805666/detecting-conflict-in-day-vb-6-0-and-ms-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!