Public Function Anniversary(ByVal pDate As Date, Optional pNextOne As Boolean = False) As Date
'*******************************************
'Name: Anniversary (Function)
'Purpose: Return this years' or the next
' anniversary of an input date
'Source: [url]http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=48683[/url]
'Author: raskew
'Goal: Six or less lines of active code
'Inputs: From debug (immediate) window:
' Note: Today's date = 02-Jun-2003
' HireDate = #4/23/99#
' (1) ? Anniversary(HireDate, True)
' (2) ? Anniversary(HireDate, False)
' (3) ? Anniversary(HireDate)
' HireDate = #8/23/99#
' (4) ? Anniversary(HireDate, True)
' (5) ? Anniversary(HireDate, False)
' (6) ? Anniversary(HireDate)
'
'Output: (1) 4/23/04
' (2) 4/23/03
' (3) 4/23/03
' (4) 8/23/03
' (5) 8/23/03
' (6) 8/23/03
'*******************************************
Dim myDate As Date
myDate = pDate
'this line provides the anniversary date occuring this year
myDate = DateSerial(Year(Date), Month(myDate), day(myDate))
'this line allows the user to specify the next scheduled anniversary
'if this years' anniversary has already past
'note that the second and third options come into play only if pNextOne = True
myDate = Switch(pNextOne = False, myDate, myDate < Date, DateAdd("yyyy", 1, myDate), True, myDate)
Anniversary = myDate
End Function