Quote:
Originally Posted by karimufeed
I am working on an access project for pension calculation. I want to generate the retirement date automatically at the age of 60 years while filling the date of Birth. i.e. if the Date of birth is 15/1/1950 then the date of retirement will be 31/1/2010 and if the date of birth is 01/1/1950 then the date of retirement will be 31/12/2009 one day earlier.
Kindly help me how to generate the date of retirement by using VB code in an access project.
Hi
I feel sure that you have not given us all your requirements, but this does exactly what you have specified
- Sub Test()
-
Dim DOB As Date
-
Dim RetirementDate As Date
-
-
DOB = "15/01/1950"
-
-
RetirementDate = DateSerial(Year(DOB - 1) + 60, Month(DOB - 1) + 1, 1) - 1
-
-
MsgBox RetirementDate
-
-
End Sub
I am not sure what you want to happen with any other dates in the month/year !?
If you are not familiar with the DateSerial() function then I suggest you look at Help for more explanation, but all I can say is it is extremely flexible for calculating dates (more so than DateAdd() and DateDiff() IHMHO).
HTH
MTB