Hi all,
I am quite new to VBA and i wrote the following function. I try to double check if there is any double booking for a time slot. And now i need to add if the room is available, but i am still stuck how to add the room availability logic. Could someone please help? Thanks in advance.
Private Function IsConflicts(SD As Date, ED As Date) As Boolean
Dim ID As Long
'check start date and room availability
ID = Nz(DLookup("OrderID", "OrderT", _
"OrderID <>" & OrderID & " AND " & _
"StartDateTime<=#" & SD & "# AND " & _
"EndDateTime > #" & SD & "# AND " & _
"RoomID = " & RoomID), 0) ' <-- i tried to add this here, but couldn't get through if i change the room type with the same time slot.
If ID = 0 Then
' check end date
ID = Nz(DLookup("OrderID", "OrderT", _
"OrderID <>" & OrderID & " AND " & _
"StartDateTime<#" & ED & "# AND " & _
"EndDateTime >= #" & ED & "#"), 0)
End If
If ID = 0 Then
' check for spanning appointments
ID = Nz(DLookup("OrderID", "OrderT", _
"OrderID <>" & OrderID & " AND " & _
"StartDateTime>#" & SD & "# AND " & _
"EndDateTime < #" & ED & "#"), 0) ' need to check logic
End If
If ID <> 0 Then
IsConflicts = True
Else
IsConflicts = False
End If
End Function
I am quite new to VBA and i wrote the following function. I try to double check if there is any double booking for a time slot. And now i need to add if the room is available, but i am still stuck how to add the room availability logic. Could someone please help? Thanks in advance.
Private Function IsConflicts(SD As Date, ED As Date) As Boolean
Dim ID As Long
'check start date and room availability
ID = Nz(DLookup("OrderID", "OrderT", _
"OrderID <>" & OrderID & " AND " & _
"StartDateTime<=#" & SD & "# AND " & _
"EndDateTime > #" & SD & "# AND " & _
"RoomID = " & RoomID), 0) ' <-- i tried to add this here, but couldn't get through if i change the room type with the same time slot.
If ID = 0 Then
' check end date
ID = Nz(DLookup("OrderID", "OrderT", _
"OrderID <>" & OrderID & " AND " & _
"StartDateTime<#" & ED & "# AND " & _
"EndDateTime >= #" & ED & "#"), 0)
End If
If ID = 0 Then
' check for spanning appointments
ID = Nz(DLookup("OrderID", "OrderT", _
"OrderID <>" & OrderID & " AND " & _
"StartDateTime>#" & SD & "# AND " & _
"EndDateTime < #" & ED & "#"), 0) ' need to check logic
End If
If ID <> 0 Then
IsConflicts = True
Else
IsConflicts = False
End If
End Function