Simplest approach might be to make a multi-field unique indexes on the
relevant fields in the appointments table
Guessing at your rules, since you did not supply specifics
Rule 1) An engineer can have only one appointment with a customer per day.
--- Unique Index on Engineer, Customer, and Date fields
Rule 2) An Engineer can have only one appointment at a specific date and
time
--- Unique index on Engineer, Date, and Time fields
This one is more complex since you probably need to look for overlapping
dates and times and this cannot be done with any simple index or validation
rule in Access. You would need a query that checked for overlaps. Since
your appointments table does not have a duration for the visit or a start
AND end time for appointments, there is no solution that I can see to
prevent an engineer from having overlapping appointments
Rule 3) Only one engineer per customer per day
--- Unique index on customer and date fields.
All three of those will generate an error when you attempt to save the
record that would violate the rules of the index.
To create a multiple field unique index (Compound index)
--Open up the WorkingTable in design mode
--Select View: Index from the menu
--Enter Name for Index in first blank cell under Index Name
--Select one field in the index under Field Name
--Set Unique to Yes
--Move down one line and select the next FieldName
--Continue moving down and selecting fieldnames until all needed are
included.
--Close the index window and close and save the table
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.
- Show quoted text -
Hi John, thanks for the response. To answer some of your questions,
lets assume the following:
a) An engineers day is booked by 2 hour slots. 8-10, 10-12, 13-15,
15-17 '00 hours.
b) Any customer can book an engineer twice in a day
c) An engineer simply cannot be booked for the same time slot in the
same day.
My appointments table will allow the user to choose a time slot. If I
have another table called time slots with Id's, e.g. ID = 1 , Time =
8am, ID = 2, Time = 10am etc linked to the appointments table, so by
creating an appointment, you choose a time slot
Therefore, if I can query the time slots that are free for an engineer
on a day, I should be able to use that as the source for a combobox
for users to select from. Therefore, they will not be able to choose a
time slot that has already been used.
My query to thus far has Appointments table for engineer id, date and
from TimeSlots table for all timeslots in a day. The results will show
me all the bookings for an engineer, the date and what time slots. If
I can create another query to exclude the results of the previous
query, ie time slots that has been used, that should show me free time
slots
Any ideas?