Suppose your year is in the textbox Me.txtYear. Then...
Dim dtm1stMonday As Date, dtmDate As Date, bytWeekNo As Byte
'Assume first Monday is January 1.
dtm1stMonday = DateSerial(Me.txtYear, 1, 1)
'Correct date if it's NOT Monday.
dtm1stMonday = DateAdd("d", 2 - Weekday(dtm1stMonday), dtm1stMonday)
'If correction places you in last Monday of previous year, correct THAT.
If Year(dtm1stMonday) < Me.txtYear Then
dtm1stMonday = DateAdd("d", 7, dtm1stMonday)
End If
dtmDate = dtm1stMonday
For bytWeekNo = 1 To 52
MsgBox Me.txtYear & " " & bytWeekNo & " " & dtmDate, vbInformation, "Mondays in Year"
dtmDate = DateAdd("d", 7, dtmDate)
Next bytWeekNo
Change the MsgBox statement in this code to actually assign the bytWeekNo and dtmDate to other textboxes if you wish.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|