I have one main form named "Events" that is used to schedule these rooms.
The "Events" form has several fields on it such as "Building" which is a Combo box with the name "cmbBuilding". There's a field below "Building" named "Location" which is called "cmbLocation". The 2 fields Building and Location are related because when someone chooses a buildling from the list, it modified what options are available in the Location drop down box since different buildings have different rooms on different floors. I have a Locations table, and a Buildings table, which the form uses to populate the drop down boxes.
Below the Location field is "cmbStartDate", "cmbEndDate", "txtStartTime", "txtEndTime" and other fields that are not related to my question.
The "Events" form updates an "Events" table which has these Field Names:
"Location", "Building", "StartDate", "EndDate", "StartTime", "EndTime".
I want to prevent locations from being double booked.
Example:
Person 1 schedules wants to reserve a room in Atlanta (cmbBuilding on form, Building on table). They choose Atlanta from the Building drop down box on the form and the Location drop down box below it gets modified to only show rooms in Atlanta. They then pick a date from a calendar control that populates the StartDate and EndDate fields on the form (cmbStartDate and cmbEndDate on the form but StartDate and EndDate on the table). The dates are autoformatted to this format : MM/DD/YYYY ... or M/D/YYYY if the month and day happen to be less than 10 (in other words, it doesn't put in the leading 0 if less than 10 e.g. not 01/03/2008, simply 1/3/2008). They then enter a StartTime and EndTime (txtStartTime and txtEndTime on the form, StartTime and EndTime on the table).
So... Atlanta - 5th Floor - 3/23/2008 through 3/25/2008 from 09:00am untill 01:00pm on each of those days.
If this reservation was made, I don't want anyone to be able to schedule a date for Atlanta on the 5th floor, between 3/23/2008 and 3/25/2008 between the hours of 9 am to 1pm. However they should still be able to schedule a meeting from 8am to 9am on between 3/23/2008 and 3/25/2008, and they should also still be able to schedule something after 1pm on 3/23/2008 through 3/25/2008.
I reviewed the discussion on these forums at the following pages:
http://www.thescripts.com/forum/thread604404.html
http://www.thescripts.com/forum/thread607917.html
And thought it might be possible to modify the code they suggested that would help him in his situation:
Expand|Select|Wrap|Line Numbers
- Dim db As DAO.Database
- Dim rs As DAO.Recordset
- Dim strMessage As String
- Dim StartTime As Date
- Dim EndTime As Date
- Dim test As Boolean
- test = False
- If Me.NewRecord = True Then
- Set db = CurrentDb
- Set rs = db.OpenRecordset("SELECT [ScheduleStartTime], [ScheduleEndTime] " & _
- "FROM Schedule INNER JOIN ScheduleDetails " & _
- "ON Schedule.ScheduleID=ScheduleDetails.ScheduleID " & _
- "WHERE [CourtID]=" & Me.[BookingsSubform].Form![CourtID] & " " & _
- "AND [ScheduleDate]=#" & Me.[BookingsSubform].Form![ScheduleDate] & "#")
- StartTime = Me.[BookingsTimeSubform].[Form]![ScheduleStartTime]
- EndTime = Me.[BookingsTimeSubform].[Form]![ScheduleEndTime]
- If rs.RecordCount = 0 Then Exit Sub
- rs.MoveFirst
- Do Until rs.EOF
- If StartTime = rs!ScheduleStartTime Or EndTime = rs!ScheduleEndTime Then
- test = True
- ElseIf StartTime > rs!ScheduleStartTime And StartTime < rs!ScheduleEndTime Then
- test = True
- ElseIf EndTime < rs!ScheduleEndTime And EndTime > rs!ScheduleStartTime Then
- test = True
- End If
- If test Then
- rs.MoveLast
- Else
- rs.MoveNext
- End If
- Loop
- If test = False Then
- MsgBox ("Time is available")
- Else
- MsgBox ("Time is unavailable")
- Me.ScheduleStartTime = Null
- Me.ScheduleEndTime = Null
- End If
- rs.Close
- Set rs = Nothing
- Set db = Nothing
- End If
Please help if at all possible.
Thank You