Public Function basTuesAftrMon(dtIn As Date, DOW As Integer) As Date
'Michael Red 12/4/03 Tek-tips thread702-721983 for haytatreides
'Borrows from previous development dtNthDOW Returns the Nth occurance _
of a Day of the week within a month
Dim Mydt As Date
Mydt = dtNthDOW(dtIn, 1, vbMonday)
While Weekday(Mydt) <> DOW
Mydt = Mydt + 1
Wend
basTuesAftrMon = Mydt
End Function
[\code]
[code]
Public Function dtNthDOW(dtDtIn As Date, intNthWkDay, Optional intDOW As Variant) As Date
'Michael Red 11/8/2003 Return the Date of the Day of the Week [intDOW] _
following the Nth Day of the Month _
in the Month of the input date. Minimal error checking, Returns Sone _
date in the year of 1899 if the Nth Day of the Week does not fall in _
the same month as the date in.
'Examples of normal returns
'? dtNthDOW(date, 1, vbMonday)
'12/3/03
'dtNthDOW(#11/12/03#, 1, vbTuesday)
'11/4/03
'Example of an error return
'? dtNthDOW(DAte, 6, vbsunday)
'12/29/1899
Dim dtFstOfMnth As Date
If (IsMissing(intDOW)) Then
intDOW = vbFriday
End If
dtFstOfMnth = DateSerial(Year(dtDtIn), Month(dtDtIn), 1)
While Weekday(dtFstOfMnth) <> intDOW
dtFstOfMnth = dtFstOfMnth + 1
Wend
dtNthDOW = DateAdd("d", (intNthWkDay - 1) * 7, dtFstOfMnth)
If (Month(dtDtIn) <> Month(dtNthDOW)) Then
dtNthDOW = -1
End If
End Function