I have a logic problem that is driving me insane and wonder if someone can help.
I have a bound form listing a number of room booking records and I wish to select one of them and change the booking. However, before I save the edit I need to check that the edit will not conflict with any other bookings within the table. My problem comes when I try to check the edit and my code for this is as follows:-
I am using the record ID to try and ignore the record being edited from the SQL search by putting [BookID] <> Me.BookID within the SQL. My perception here was the the search would ignore the current record and simply test the remaining ones? However, the SQL results in Validation Success each time (even though I try a change I know will conflict).
The results are illogical but I am obvioiusly missing something here.
I never realised that editing in a bound form could be so complicated and am wondering if my approach to this is completely wrong.
Any advice would be greatly appreciated.
I have a bound form listing a number of room booking records and I wish to select one of them and change the booking. However, before I save the edit I need to check that the edit will not conflict with any other bookings within the table. My problem comes when I try to check the edit and my code for this is as follows:-
Code:
dteDate = Me!BookStartDate
strRoom = Me!BookLocation
dteStartTime = Me!BookTime
dteEndTime = Me!BookEndTime
BookRef = Me.BookID
Valid = 0
MsgBox ([BookID] & BookRef)
' The SQL String Variable below takes the info entered in the booking form to compare a table record.
' WILL NOT WORK ?????
strSQL = "([BookStartDate] = #%D#) AND " & _
"([BookLocation] = '%R') AND " & _
"([BookTime] < #%E#) AND " & _
"([BookEndTime] > #%S#) AND " & "([BookID] <> '%T')"
strSQL = Replace(strSQL, "%D", Format(dteDate, "d/m/yyyy")) ' Substitues form date to % variables
strSQL = Replace(strSQL, "%R", strRoom)
strSQL = Replace(strSQL, "%E", Format(dteEndTime, "H:m:s"))
strSQL = Replace(strSQL, "%S", Format(dteStartTime, "H:m:s"))
strSQL = Replace(strSQL, "%T", BookRef)
Valid = (DCount("*", "tblRoomsBooking", strSQL))
If Valid > 0 Then
MsgBox ("Your Change Confilcts with a Prior Prior Booking, this cannot be completed")
Me.Undo
Invalid = True
GoTo Ender
Exit Sub
Else
MsgBox ("Change is Valid and saved into Database, The old Oulook Appointment will now be deleted")
DoCmd.RunCommand acCmdSaveRecord 'Ensure the changed booking is saved
GoTo Delete_Old_Appointment
End If
The results are illogical but I am obvioiusly missing something here.
I never realised that editing in a bound form could be so complicated and am wondering if my approach to this is completely wrong.
Any advice would be greatly appreciated.