But I have a much better Idea.
We can simplify this and make it much more stable. If I new your format would end up like this instead of linear calendars I would have suggested this in the first place. Make a single "Month" calendar. Copy one month and paste into a new form. Called "subFormMonth". Size that form to the size of the calendar. Change the name of the month label to "lblMonthName". In that month rename your labels and textboxes.
Change the naming convention
from txtJan1 to txt1,txt2...
and lblJan1 to lbl1, lbl2,lbl3
Now build a brand new form
Add the header and footer
Add a subform control with your new monthsubform
Play with the formatting (no scroll bars, navigation buttons, record selectors ...) and size until it looks good. Should look identical to what you have. Except instead of 12 calendars made of controls you will have 12 subforms
Copy and paste the subform control 11 times.
Name your subform controls
subFormJan, subFormFeb .....
Now in your fill labels module add a new procedure. Very little modifications, basically just take the loop out.
Code:
Public Sub FillSubFormMonthLabels(frm As Access.Form, TheYear As Integer, TheMonth As Integer)
'==================================================================================================
'//Fills the grids label(s) with the correct day and;
' 1) Hides day labels that dont have a date associated with them
' 2) Disable and locks text boxes without a date so data cant be entered
'==================================================================================================
Dim ctl As Access.Label
Dim ctlt As Access.TextBox 'Added to disable/lock text boxes without a date so data cant be entered
Dim i As Integer
Dim FirstDayOfMonth As Date 'First of month
Dim DaysInMonth As Integer 'Days in month
Dim intOffSet As Integer 'Offset to first label for month.
Dim intDay As Integer 'Day under consideration.
Dim monthCounter As Integer
Const ctlBackColor = 14211288 'Gray color thats used for Holiday shading/unshading
FirstDayOfMonth = getFirstOfMonth(TheYear, monthCounter)
DaysInMonth = getDaysInMonth(FirstDayOfMonth) 'Days in month.
intOffSet = getOffset(TheYear, monthCounter, vbSaturday) 'Offset to first label for month.
For i = 1 To 37
Set ctl = frm.Controls("lbl" & i)
Set ctlt = frm.Controls("txt" & i) 'Added to disable/lock text boxes without a date so data cant be entered
ctl.Caption = ""
ctl.BackColor = ctlBackColor 'Resets the backcolor to Gray
intDay = i - intOffSet 'Transforms label number to day in month
If intDay > 0 And intDay <= DaysInMonth Then
ctl.Caption = intDay 'Displays day number in correct label
ctlt.Enabled = True 'Added to enable textbox(s) that have a date associated with them
ctl.Visible = True 'Added so the months labels that display a date show on the grid
Else
ctlt.Enabled = False 'Added to disable/lock text boxes without a date so data cant be entered
ctl.Visible = False 'Added so months lables that don't display or have a date do not show on grid
End If
Next i
End Sub
Now on your main form you will need code something more like this.
Code:
Public subfrmJan As Form_subFormMonth
Public subFrmFeb As Form_subFormMonth
... one for each
Private Sub Form_Load()
Set subfrmJan = Me.subFormJan.Form
Set subFrmFeb = Me.subFormFeb.Form
...
UpdateAllCalendars
End Sub
Of course you will have to do similar modification to the fill textboxes.
FillSubFormTextBoxes(frm As Access.Form, empID As Long, TheYear As Integer, TheMonth as Integer)
...
strSQL = "Select * from qry_FillTextBoxes where EmployeeID = " & empID 'Query that finds the absence Year() by employeeID
strSQL = strSQL & " AND year(AbsenceDate) = " & TheYear & " AND Month(absenceDate) = " & TheMonth
In your Main Form you then would likely want methods like
Code:
Public Sub UpdateAllCalendars
subfrmJan.LblMonth.Caption = "January"
subFrmFeb.LblMonth.Caption = "February"
...
mod_FillMonthLabels.FillSubFormMonthLabels subfrmJan, me.comboYear, 1
mod_FillMonthLabels.FillSubFormMonthLabels subFrmFeb, me.comboYear, 2
...
Now you should be able to figure out how to update the textboxes for each or one subform calendar
You will go from 100s of controls to tens of controls (the subforms are 1 control). Also the ability to modify the form will greatly increase. I can barely edit it now.