Question : First Day of the Week

I have a database where I wish to populate a combo box with the dates of the first day of the week for the whole year. ex: Mondays for January 2005 would provide the options: 1/3/2005,1/10/2005,1/17/2005.........  Your thoughts?

Answer : First Day of the Week

Here's another version of the same sub that allows you to pass a year to it:

Public Function PopulateMondays(strYear As String) As String
Dim x As String
Dim strReturn As String

PopulateMondays = ""
If ((Nz(strYear, "") = "") Or (Not IsNumeric(strYear)) Or (Len(strYear) <> 4)) Then
    MsgBox "The parameter must be a valid 4-digit year"
    Exit Function
End If

x = "1/1/" & strYear

Select Case Weekday(x)
    Case 1: x = DateAdd("d", 1, x)
    Case 3, 4, 5, 6, 7: x = DateAdd("d", 9 - Weekday(x), x)
End Select

strReturn = ""
Do
    strReturn = strReturn & x & ";"
    x = DateAdd("d", 7, x)
Loop Until strYear <> Year(x)

PopulateMondays = strReturn

End Function
Random Solutions  
 
programming4us programming4us