A few days ago a couple of helpful readers gave me some code to place on the BeforeUpdate event of the lstTimes list box.
It worked perfectly but suspect I may have erroneously overwrote it with an older database copy and, if so, of course it no longer exists.
I re-introduced it as shown below and it doesn't work. I then changed the line containing Format(Me.AppointmentDate, "mm/dd/yyyy") to read
Format(Me.txtAppointmentDate, "mm/dd/yyyy"), and then tried Format(AppointmentDate, "dd/mm/yyyy") but none work and I cannot see why.
Basically I have two tables (listed below are the pertinent fields
tblAppointments
AppointmentRef - AutoNumber, Long Integer, Promary Key
AppointmentDate - Date Time set to Short Date
AppointmentTimeID Foreign key from tblAppopintmentTimes - Long Integer
tblAppointmentTimes
AppointmentTimeID - AutoNumber, Long Integer, Promary Key
AppointmentTime - Date Time set to Short Time
What I am trying to achieve is to have code on the BeforeUpdate event to ensure that appointments are not doubled booked.
When the user tries to schedule an appointment, for a time that has already been booked on that day, they should receive an error message and the event is cancelled.
The code I was given is
Private Sub lstTimes_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblAppointments", "AppointmentDate=#" & Format(Me.AppointmentDate, "mm/dd/yyyy") & "# AND ApptTimeID=" & Me.lstTimes) > 0 Then (NB Me.AppointmentDate is formatted to dd/mm/yy on the form)
MsgBox "The appointment time for the indicated date has already been reserved"
Cancel = True
End If
End Sub
On the attached form the relative control names are
txtAppointmentRef
txtAppointmentDate
lstTimes - list box containing the times
I should add that Fecha means Date and Tiempo de Cita is Appointment Time whose drop down list is lstTimes.
You can see from theb datasheet below that currently times are being multi booked.
Any assistance greatly appreciated
Regards
Cheyanne