I am trying to represent on a form time slots I have re-created the look of an outlook calendar on the form I have a table with the calendar bookings start and end time and there could be any number of bookings in a day. The following code represents the column for the first day of the week (monday) and formats the text boxes accordingly if the room is booked.
This all works fine but I have to have this code again to represent the secound day (tuesday) third day, fourth day etc
I have got it working for Monday, Tuesday and Wednesday but if I go any further I am getting the error message "compile error procedure too large" I have to repeat this process for anywhere up to 20 calendars is there any way that I can cut this code down so that is not too large for access to handle
Any help is much appreciated
Regards Phill
Expand|Select|Wrap|Line Numbers
- Dim dbsEquipBook As DAO.Database
- Dim rstCheck As DAO.Recordset
- Dim qdf As DAO.QueryDef
- Dim MyDate, MyWeekDay
- Dim FirstDay As Date
- Dim LastDay As Date
- Dim MondayForm As Date
- Dim TuesdayForm As Date
- Dim WednesdayForm As Date
- Dim ThursdayForm As Date
- Dim FridayForm As Date
- Dim SaturdayForm As Date
- Dim SundayForm As Date
- Dim BookedStartTimeDate As Date
- Dim BookedEndTimeDate As Date
- Dim BookedStartTime As Date
- Dim BookedEndTime As Date
- Dim txtMon0800 As Date
- Dim txtMon0830 As Date
- Dim txtMon0900 As Date
- Dim txtMon0930 As Date
- Dim txtMon1000 As Date
- Dim txtMon1030 As Date
- Dim txtMon1100 As Date
- Dim txtMon1130 As Date
- Dim txtMon1200 As Date
- Dim txtMon1230 As Date
- Dim txtMon1300 As Date
- Dim txtMon1330 As Date
- Dim txtMon1400 As Date
- Dim txtMon1430 As Date
- Dim txtMon1500 As Date
- Dim txtMon1530 As Date
- Dim txtMon1600 As Date
- Dim txtMon1630 As Date
- Dim txtMon1700 As Date
- Dim txtMon1730 As Date
- Dim txtMon1800 As Date
- Dim txtMon1830 As Date
- Dim txtMon1900 As Date
- Dim txtMon1930 As Date
- Dim txtMon2000 As Date
- Dim txtMon2030 As Date
- Dim txtMon2100 As Date
- Dim txtMon2130 As Date
- Dim txtMon2200 As Date
- Dim txtMon2230 As Date
- Dim txtMon2300 As Date
- Dim txtMon2330 As Date
- 'this checks to see if euipment is booked then populates sform with time info which is then picked up by conditional formatting
- Set dbsEquipBook = CurrentDb()
- Set qdf = dbsEquipBook.QueryDefs("QSelS104calcheck")
- qdf.Parameters(0) = [Forms]![FrmCalendarMain]![SfrCalS104].[Form]![TxtMon]
- qdf.Parameters(1) = [Forms]![FrmCalendarMain]![SfrCalS104].[Form]![sun]
- 'works out the first and last day of the week acoording to the selected date from mydate which is a calendar control on the form that the user selects
- MyDate = [Forms]![FrmCalendarMain].[frmCalendar]![txtDate]
- MyWeekDay = Weekday(MyDate)
- FirstDay = MyDate - MyWeekDay + 2
- LastDay = MyDate - MyWeekDay + 8
- 'writes the first and last date to form
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon] = FirstDay
- [Forms]![FrmCalendarMain].[SfrCalS104]![sun] = LastDay
- MondayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon]
- TuesdayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![tues]
- WednesdayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![weds]
- ThursdayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![thurs]
- FridayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![fri]
- SaturdayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![sat]
- SundayForm = [Forms]![FrmCalendarMain].[SfrCalS104]![sun]
- Set rstCheck = qdf.OpenRecordset(dbOpenDynaset, dbReadOnly)
- Do While Not rstCheck.EOF
- BookedStartTimeDate = Format(rstCheck!StartDate, "dd mm yyyy")
- BookedEndTimeDate = Format(rstCheck!EndDate, "dd mm yyyy")
- If BookedStartTimeDate = MondayForm Then
- BookedStartTime = Format(rstCheck!StartDate, "hh:nn")
- BookedEndTime = Format(rstCheck!EndDate, "hh:nn")
- ''this is here to handle the midnight time issue
- If BookedEndTime = "00:00:00" Then
- BookedEndTime = "23:59:59"
- End If
- 'this picks up the value of the text boxes on the form that represent the time slots
- txtMon0800 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:00]
- txtMon0830 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:30]
- txtMon0900 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:00]
- txtMon0930 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:30]
- txtMon1000 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:00]
- txtMon1030 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:30]
- txtMon1100 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:00]
- txtMon1130 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:30]
- txtMon1200 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:00]
- txtMon1230 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:30]
- txtMon1300 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:00]
- txtMon1330 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:30]
- txtMon1400 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:00]
- txtMon1430 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:30]
- txtMon1500 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:00]
- txtMon1530 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:30]
- txtMon1600 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:00]
- txtMon1630 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:30]
- txtMon1700 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:00]
- txtMon1730 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:30]
- txtMon1800 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:00]
- txtMon1830 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:30]
- txtMon1900 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:00]
- txtMon1930 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:30]
- txtMon2000 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:00]
- txtMon2030 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:30]
- txtMon2100 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:00]
- txtMon2130 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:30]
- txtMon2200 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:00]
- txtMon2230 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:30]
- txtMon2300 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:00]
- txtMon2330 = [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:30]
- 'this checks through to see if there is a calendar entry and formats the text boxes accordingly for the monday colum
- If txtMon0800 >= [BookedStartTime] And txtMon0800 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:00].Enabled = False
- End If
- If txtMon0830 >= [BookedStartTime] And txtMon0830 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon08:30].Enabled = False
- End If
- If txtMon0900 >= [BookedStartTime] And txtMon0900 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:00].Enabled = False
- End If
- If txtMon0930 >= [BookedStartTime] And txtMon0930 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon09:30].Enabled = False
- End If
- If txtMon1000 >= [BookedStartTime] And txtMon1000 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:00].Enabled = False
- End If
- If txtMon1030 >= [BookedStartTime] And txtMon1030 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon10:30].Enabled = False
- End If
- If txtMon1100 >= [BookedStartTime] And txtMon1100 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:00].Enabled = False
- End If
- If txtMon1130 >= [BookedStartTime] And txtMon1130 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon11:30].Enabled = False
- End If
- If txtMon1200 >= [BookedStartTime] And txtMon1200 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:00].Enabled = False
- End If
- If txtMon1230 >= [BookedStartTime] And txtMon1230 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon12:30].Enabled = False
- End If
- If txtMon1300 >= [BookedStartTime] And txtMon1300 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:00].Enabled = False
- End If
- If txtMon1330 >= [BookedStartTime] And txtMon1330 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon13:30].Enabled = False
- End If
- If txtMon1400 >= [BookedStartTime] And txtMon1400 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:00].Enabled = False
- End If
- If txtMon1430 >= [BookedStartTime] And txtMon1430 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon14:30].Enabled = False
- End If
- If txtMon1500 >= [BookedStartTime] And txtMon1500 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:00].Enabled = False
- End If
- If txtMon1530 >= [BookedStartTime] And txtMon1530 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon15:30].Enabled = False
- End If
- If txtMon1600 >= [BookedStartTime] And txtMon1600 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:00].Enabled = False
- End If
- If txtMon1630 >= [BookedStartTime] And txtMon1630 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon16:30].Enabled = False
- End If
- If txtMon1700 >= [BookedStartTime] And txtMon1700 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:00].Enabled = False
- End If
- If txtMon1730 >= [BookedStartTime] And txtMon1730 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon17:30].Enabled = False
- End If
- If txtMon1800 >= [BookedStartTime] And txtMon1800 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:00].Enabled = False
- End If
- If txtMon1830 >= [BookedStartTime] And txtMon1830 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon18:30].Enabled = False
- End If
- If txtMon1900 >= [BookedStartTime] And txtMon1900 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:00].Enabled = False
- End If
- If txtMon1930 >= [BookedStartTime] And txtMon1930 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon19:30].Enabled = False
- End If
- If txtMon2000 >= [BookedStartTime] And txtMon2000 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:00].Enabled = False
- End If
- If txtMon2030 >= [BookedStartTime] And txtMon2030 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon20:30].Enabled = False
- End If
- If txtMon2100 >= [BookedStartTime] And txtMon2100 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:00].Enabled = False
- End If
- If txtMon2130 >= [BookedStartTime] And txtMon2130 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon21:30].Enabled = False
- End If
- If txtMon2200 >= [BookedStartTime] And txtMon2200 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:00].Enabled = False
- End If
- If txtMon2230 >= [BookedStartTime] And txtMon2230 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon22:30].Enabled = False
- End If
- If txtMon2300 >= [BookedStartTime] And txtMon2300 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:00].Enabled = False
- End If
- If txtMon2330 >= [BookedStartTime] And txtMon2330 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:30].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:30].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon23:30].Enabled = False
- End If
- If txtMon0000 >= [BookedStartTime] And txtMon0000 < [BookedEndTime] Then
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon00:00].BackColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon00:00].ForeColor = RGB(191, 191, 191)
- [Forms]![FrmCalendarMain].[SfrCalS104]![TxtMon00:00].Enabled = False
- End If
- End If
- rstCheck.MoveNext
- Loop
- rstCheck.Close