khch
Because you need to include start / end time, the problem is pretty tough, BUT there is one thing you should do regardless of code. You can use the "primary key" or unique index to minimize double bookings. But this is still not enough.
A reservation is actually a many-to-many relationship between the reservered item and the person making the reservation.
- A person can reserve many items
- An item can be reserved many times.
Your reservation table is actually the joiner or intermediary table.
Consequently, the start of the design of the reservation table is to include Person + Item.
But since a person can reserve an item multiple times, you need to include the date and time.
tblRservation
ItemCode - foreign key to item table
ContactID - foreign key to contact or customer table
DateOut
TimeOut
Your primary key for this table should be
ItemCode + ContactID + DateOut
if the item can only be reservered once during a day
ItemCode + ContactID + DateOut + TimeOut
or
ItemCode + ContactID + (Date+Time)
if the item can only be reservered several times during a day
The first scenario is the easiest. But the adding time component really adds complexity.
What makes it tough is that although you can block an item on this date at this time, you can not block an item at this date at this time - 1 min, or + 1 min.
Example:
The DVD Lord of the Rings, FOTR is
- signed out July 2, 2PM
- signed in July 3, 3 PM
But the same DVD can also be
- signed out Jul 2 6PM
[COLOR=blue yellow]
You need to also keep a flag on the Item table indicating that it is signed out.[/color]
...Moving on
Assuming that
- ItemCode is a string variable used as the primary key to reserve your item, and is referenced on the form as Me.ItemCode
- you have added a field to the Item table CheckedOut (Yes/No boolean), using
AceMan's excellent post...
Code:
Criteria = "[ItemCode] = " & "'" & Me.ItemCode & "'"
If (DLookup("[CheckedOut]", "YourItemTable", Criteria)) Then...
Therefore, when you check out an item, not only do you have to make the reservation, you also have to flag the item as reserved. And then complete the reservation with the CheckIn Date and Time, and uncheck the CheckOut flag.
As a user friendly gesture, if an Item is checked out, your message could indicate who has the item reserved.
This is a real interesting issue since normalization of the reservation table does not present the best solution.
SideBar: AceMan -- I really liked your snippet of code
Richard