D
dzabor
Guest
I need a formula to have an anniversay date returned basing it on a [date hired] field. Can you help me?
dzabor
dzabor
Last edited:
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
SELECT [Employee Master File].[Last Name], [Employee Master File].[First Name], [Employee Master File].[Employee #], [Employee Master File].[Hire Date], [Employee Master File].Status
FROM [Employee Master File]
WHERE (((Date() = DateAdd("m",11,[Employee Master File].[Hire Date])) AND (([Employee Master File].Status)="A"));
I now get Syntax error in query expression with this.
Sorry, didn't know, as soon as I figure out how to close this I will.