Function NextNDay(ByVal pDay As Date, wday As Integer) As Date
NextNDay = [pDay] - WeekDay([pDay]) + wday + IIf(WeekDay([pDay]) >= wday, 7, 0)
End Function
...which you can call from the debug window with:
? nextnday(#10/21/02#, vbFriday)
10/25/02
To go in the opposite direction, try:
Code:
Function LastNDay(pDay As Date, wday As Integer) As Date
LastNDay = [pDay] - (WeekDay([pDay]) + IIf(WeekDay([pDay]) <= wday, 7, 0) - wday)
End Function
...which would return the previous specified day, e.g.