I am afraid I am back to an old question which I thought I had resolved. I am now UAT testing and have found that the logic of my SQL statement does not work.
I have the following records in a table and want to edit a record and validate the change before saving it. This is the result of the qryBookings that my Dcount function evaluates the SQL against.
However, If I change record 1 to Room 2 and keep the same date/time the Sql says it is Invalid. Also if I change Record 3 to 6/11/2011 and start time to 1:30PM it says it is Invalid. Both of these changes should be valid?
If I change Record 1 to Room 3 it validates OK?
Here is the code I am using for which I received a lot of help.....I thought it worked OK at the Time???
I really thought I had put this to bed but obviously not. I will enclose the small database (saved in 2003 format) in order that you can see for yourselves that the validation is not correct.
Sorry to repeat the question guys but I now realise how difficult working wuth date & time is. I feel there is perhaps an OR statement missing or something?
I have the following records in a table and want to edit a record and validate the change before saving it. This is the result of the qryBookings that my Dcount function evaluates the SQL against.
Code:
BookStartDate BookLocation BookTime_ BookEndTime_ BookID 06/11/2011 Room 10:30 AM 01:30 PM 1 06/11/2011 Room 2 01:30 PM 06:30 PM 2 08/11/2011 Room 2 11:00 AM 05:30 PM 3 10/11/2011 Room 2 02:30 PM 05:00 PM 4
If I change Record 1 to Room 3 it validates OK?
Here is the code I am using for which I received a lot of help.....I thought it worked OK at the Time???
Code:
StrSQL = "([BookStartDate] = " & Format(dteDate, "\#mm\/dd\/yyyy\#") & ") AND " & _ "([BookLocation] = '" & strRoom & "') AND " & _ "([BookTime] < #" & Format(dteEndTime, "Hh:Nn:Ss AM/PM") & "#) AND " & _ "([BookEndTime] > #" & Format(dteStartTime, "Hh:Nn:Ss AM/PM") & "#) AND " & "([BookID] <> " & BookRef & ")" If Nz(DCount("*", "qryBookings", StrSQL), 0) <> 0 Then MsgBox ("Your Change Confilcts with a Prior Prior Booking, this cannot be completed") Me.Undo 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
Sorry to repeat the question guys but I now realise how difficult working wuth date & time is. I feel there is perhaps an OR statement missing or something?
Comment