RandomGuy123
Registered User.
- Local time
- Today, 08:12
- Joined
- Feb 12, 2014
- Messages
- 15
Sorry, I thought you had the logic already on your button. Try this:
Code:Private Sub Command24_Click() If CheckDoubleBook(Me.RoomID, Me.CustomerID, Me.DateStart, Me.DateEnd) Then MsgBox "There is a conflict with this reservation" Else 'Code here for not double booked End If End Sub
After trying the following code:
Code:
Public Function CheckDoubleBook(lngRoomID As Long, lngCustomerID As Long, datBookingStartDate As Date, datBookingEndDate As Date) As Boolean
'This function will return True if the room is double booked
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Bookings WHERE RoomID=" & lngRoomID & " AND CustomerID<>" & lngCustomerID & _
" AND ((BookingStartDate>=#" & datStart & "# AND BookingEndDate<#" & datEnd & "#)" & _
" OR (BookingStartDate<=#" & datStart & "# AND BookingEndDate>#" & datEnd & "#)" & _
" OR (BookingStartDate<=#" & datStart & "# AND BookingEndDate>#" & datEnd & "# AND BookingEndDate<#" & datEnd & "#)" & _
" OR (BookingStartDate>=#" & datStart & "# AND BookingStartDate<#" & datEnd & "# AND BookingEndDate>#" & datEnd & "#))")
CheckDoubleBook = Not (rs.EOF)
End Function
With the call in the command button:
Code:
Private Sub Command24_Click()
If CheckDoubleBook(Me.RoomID, Me.CustomerID, Me.BookingStartDate, Me.BookingEndDate) Then
MsgBox "There is a conflict with this reservation"
Else
'Code here for not double booked
End If
End Sub
I get the error in the JPG file named Capture 1.
When I use the other code:
Code:
Public Function CheckDoubleBook(lngRoomID As Long, datBookingStartDate As Date, datBookingEndDate As Date)
'This function will return True if the room is double booked
If DCount("[BookingID]", "Bookings", "RoomID=" & lngRoomID & _
" AND BookingStartDate<=#" & datEnd & "# AND BookingEndDate>=#" & datStart & "#") > 0 Then
CheckDoubleBook = True
Else
CheckDoubleBook = False
End If
End Function
and use the same call from the command button I get the error:
'Compile error: wrong number of arguments or invalid property assignment'
Please note that the logic that you gave me for the call for the command button:
Code:
[CODE]Private Sub Command24_Click()
If CheckDoubleBook(Me.RoomID, Me.CustomerID, Me.DateStart, Me.DateEnd) Then
MsgBox "There is a conflict with this reservation"
Else
'Code here for not double booked
End If
End Sub
I have changed it to the following - I hope I did the right thing:
Code:
Private Sub Command24_Click()
If CheckDoubleBook(Me.RoomID, Me.CustomerID, Me.BookingStartDate, Me.BookingEndDate) Then
MsgBox "There is a conflict with this reservation"
Else
'Code here for not double booked
End If
End Sub