Function GetStartDate(dteMyDate As Date, _
Optional pDay As Integer = 2) As Date
'*******************************************
'Purpose: Return the first day of a week
' based on a date input by user
' and a starting weekday (pDay)
'Coded by: raskew
'Parameters: dteMyDate: the target date
' pDay: Day of week of starting day [Sun(1) - Sat(7)]
'Inputs: from the debug window:
' ? GetStartDate(#2/22/03#, 4)
'Output: 2/19/03
'*******************************************
Dim StartDate As Date
pDay = IIf(IsMissing(pDay), 2, pDay)
If WeekDay(dteMyDate) = pDay Then
StartDate = dteMyDate
Else
StartDate = dteMyDate - (WeekDay(dteMyDate) + _
IIf(WeekDay(dteMyDate) <= pDay, 7, 0) - pDay)
End If
GetStartDate = StartDate
End Function