I think this is along the lines of what you want to do.
I created 2 tables , one for maintaing the data hour by hour and the other for maintaining the requested info. Fields used are UserId (numeric), ClassRoom (Text), StartDate (ShortDate), EndDate (ShortDate), StartHour (ShortDate), EndHour (ShortDate), DateInUse (ShortDate), HourInUse (ShortDate). Then I created a form to enter up to 3 different requests, and a command button that would first check to see if the classroom was already booked for that date and hour requested, then to add the necessary hourly records to the table tblClassroomReservations and then add the request data to table tblClassroomReservationsRequests. Here is the code behind the form that uses the following controls
txtUserID to capture one UserID
txtClassroom1, txtClassroom2, txtClassroom3 for classroom data
txtStartDate1, txtStartDate2, txtStartDate3 for starting date
txtEndDate1, txtEndDate2, txtDate3 for end date
cboStartHour1, cboStartHour2, cboStartHour3 for starting time
cboEndHour1, cboEndHour2, cboEndHour3 for ending time
cmdRequest - command button to start the process
Private Sub cmdRequest_Click()
On Error GoTo errHandler
Dim x As Integer
Dim dtEndDay As Date, dtEndTime As Date
Dim dtHourVar As Date, dtDayVar As Date
Dim db As DAO.Database, rstData As DAO.Recordset, rstReq As DAO.Recordset
Dim strFind As String
Set db = CurrentDb
Set rstData = db.OpenRecordset("tblClassroomReservations", dbOpenDynaset)
Set rstReq = db.OpenRecordset("tblClassroomReservationsRequests")
If Len(Nz(txtUserID, "")) = 0 Then
MsgBox "User ID Required", vbOKOnly, "Missing Information"
Exit Sub
End If
For x = 1 To 3
If Len(Nz(Me("txtClassroom" & CStr(x)), "")) > 0 Then
If Len(Nz(Me("txtStartDate" & CStr(x)), "")) <> 0 And Len(Nz(Me("txtEndDate" & CStr(x)), "")) > 0 And _
Len(Nz(Me("cboStartTime" & CStr(x)), "")) <> 0 And Len(Nz(Me("cboEndTime" & CStr(x)), "")) <> 0 Then
dtDayVar = Me("txtStartDate" & CStr(x))
dtEndDate = Me("txtEndDate" & CStr(x))
dtHourVar = Me("cboStartTime" & CStr(x))
dtEndTime = Me("cboEndTime" & CStr(x))
Do While dtDayVar < DateAdd("d", 1, dtEndDate)
Do While dtHourVar < dtEndTime
strFind = "Classroom = '" & Me("txtClassroom" & CStr(x)) & "' And DateInUse = #" _
& dtDayVar & "# And HourInUse = #" & dtHourVar & "#"
Debug.Print strFind
With rstData
.FindFirst strFind
If Not .NoMatch Then
Me("txtClassroom" & CStr(x)).BackColor = vbRed
Me.Repaint
MsgBox "Classroom Is already reserved for Timeframe Requested"
Exit Sub
End If
End With
dtHourVar = DateAdd("h", 1, dtHourVar)
Loop
dtDayVar = DateAdd("d", 1, dtDayVar)
dtHourVar = Me("cboStartTime" & CStr(x))
Loop
End If
End If
Next x
x = 1
For x = 1 To 3
If Len(Nz(Me("txtClassroom" & CStr(x)), "")) > 0 Then
If Len(Nz(Me("txtStartDate" & CStr(x)), "")) <> 0 And Len(Nz(Me("txtEndDate" & CStr(x)), "")) > 0 And _
Len(Nz(Me("cboStartTime" & CStr(x)), "")) <> 0 And Len(Nz(Me("cboEndTime" & CStr(x)), "")) <> 0 Then
dtDayVar = Me("txtStartDate" & CStr(x))
dtEndDate = Me("txtEndDate" & CStr(x))
dtHourVar = Me("cboStartTime" & CStr(x))
dtEndTime = Me("cboEndTime" & CStr(x))
Do While dtDayVar < DateAdd("d", 1, dtEndDate)
Do While dtHourVar < dtEndTime
With rstData
.AddNew
!UserId = txtUserID
!ClassRoom = Me("txtclassroom" & CStr(x))
!DateInUse = dtDayVar
!HourInUse = dtHourVar
.UPDATE
End With
dtHourVar = DateAdd("h", 1, dtHourVar)
Loop
dtDayVar = DateAdd("d", 1, dtDayVar)
dtHourVar = Me("cboStartTime" & CStr(x))
Loop
With rstReq
.AddNew
!UserId = Me.txtUserID
!ClassRoom = Me("txtClassroom" & CStr(x))
!StartDate = CDate(Me("txtStartDate" & CStr(x)))
!EndDate = CDate(Me("txtEndDate" & CStr(x)))
!StartHour = CDate(Me("cboStartTime" & CStr(x)))
!EndHour = CDate(Me("cboEndTime" & CStr(x)))
.UPDATE
End With
Else
MsgBox "Start and End Dates and Hours are Required", vbOKOnly, "Missing Information"
Exit Sub
End If
Else
MsgBox "Classroom Number Required", vbCritical, "Missing Data"
Exit Sub
End If
Next x
MsgBox "Completed Add Process"
errExit:
Set db = Nothing
Set rstData = Nothing
Set rstReq = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & " : " & Err.Description, vbCritical, "Error Entering Classroom Reservations"
Resume errExit
End Sub
HTH
PaulF