Code:
'this is the button's code opening report
Dim FirstDay As Integer
Dim DayIndex As Integer
Dim TextBoxIndex As Integer
Dim Done As Boolean
Dim ctlCalendar As control
Dim strNum, strSQL, upSQL As String
FirstDay = Weekday(DateSerial(Me.cmbYr, Me.cmbMth, 1)) ' Find out the first day of the week
DayIndex = 1 ' Start counting days at 1
TextBoxIndex = FirstDay
Done = False
DoCmd.OpenReport "CalenderSchedule", acViewReport
While Not (Done)
strNum = right("00" & TextBoxIndex, 2)
Set ctlCalendar = Reports("CalenderSchedule").Controls("List" & strNum)
strSQL = "SELECT Contracts.QuarryName FROM Contracts INNER JOIN workDetails ON Contracts.ContractID = workDetails.QName" _
& " WHERE Day([workDate])=" & DayIndex & " AND Month([workDate])=" & Me.cmbMth & " AND Year([workDate])=" & Me.cmbYr & ";"
Reports("CalenderSchedule").Controls("List" & strNum).RowSource = strSQL
DayIndex = DayIndex + 1
TextBoxIndex = TextBoxIndex + 1
' Are we done? Check to see if we have indexed into next month
If (Month(DateSerial(Forms!Schedule!cmbYr, Forms!Schedule!cmbMth, 1) + (DayIndex - 1)) <> Month(DateSerial(Forms!Schedule!cmbYr, Forms!Schedule!cmbMth, 1))) Then
Done = True
End If
Wend
Set ctlCalendar = Nothing
*************************************************************************
'This is the loop in report's load event.
FirstDay = Weekday(DateSerial(Forms!BlastSchedule!cmbYr, Forms!BlastSchedule!cmbMth, 1)) ' Figure out the first day of the week
DayIndex = 1 ' Start counting days at 1
TextBoxIndex = FirstDay ' Start indexing text boxes at first day in month
Done = False
While Not (Done)
' Set the value of the correct date text box
' Make a 2-digit string with the number, e.g. "01" or "08" or "12" etc.
strNum = right("00" & TextBoxIndex, 2)
Set ctlCalendar = Me("WDay" & strNum)
ctlCalendar.Value = DayIndex ' add dates to text boxes
DayIndex = DayIndex + 1
TextBoxIndex = TextBoxIndex + 1
' Are we done? Check to see if we have indexed into next month
If (Month(DateSerial(Forms!Schedule!cmbYr, Forms!Schedule!cmbMth, 1) + (DayIndex - 1)) <> Month(DateSerial(Forms!Schedule!cmbYr, Forms!Schedule!cmbMth, 1))) Then
Done = True
End If
Wend
Set ctlCalendar = Nothing
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If IsNull(ctl) = True Then
ctl.Visible = False 'hide the text boxes not required
Me("List" & right(ctl.Name, 2)).Visible = False 'hide the list boxes not required
End If
End If
Next ctl
I tried to combine the above loops but text box value could not be assigned in report's load event.
This is snapshot of part of report in design view. The bold font is for text boxes displaying date and other the list box.The textboxes are numbered as WDay01 to WDay42 and list boxes from List01 to List42.