I have a textbox (txtJobStartDate).
In order to calculate the amount of time the employee has been employed, i have another text box (txtYearsWorked) with the following control source:
=(DateDiff("d",[txtJobStartDate],[Date]()))/365
This gives me the amount of time worked as a decimal figure.
I then need to calculate whether today is an anniversary of the start date, so I need to check whether txtYearsWorked is a whole number. To do this, I have the following code in the OnCurrent section of the form:
Dim YearsWorkedWhole As Integer
Dim Remainder As Double
YearsWorkedWhole = CInt(Me.txtYearsWorked)
Remainder = Me.txtYearsWorked - YearsWorkedWhole
If Remainder = 0 Then
DoCmd.OpenForm "frmLengthOfEmploymentReminder"
End If
This works perfectly for 2000, 2001, 2002, but it doesn't work for 1999, 1998, etc.
For example
If txtJobStartDate = 24/09/00 Then txtYearsWorked = 3,
but if txtJobStartDate = 24/09/99 Then txtYearsWorked = 4.0027397260274 instead of 4.
The problem is the extra day in a leap year.
e.g. If JobStartDate = 24/09/00, then the number of days worked is 1095 days, which is divisible by 365 (=3).
But, If JobStartDate = 24/09/99, then the number of days worked is 1461 and not 1460 (as the year 2000 was a leap year). 1461 is not divisible by 365.
Any ideas on how to get around this? My head hurts.
In order to calculate the amount of time the employee has been employed, i have another text box (txtYearsWorked) with the following control source:
=(DateDiff("d",[txtJobStartDate],[Date]()))/365
This gives me the amount of time worked as a decimal figure.
I then need to calculate whether today is an anniversary of the start date, so I need to check whether txtYearsWorked is a whole number. To do this, I have the following code in the OnCurrent section of the form:
Dim YearsWorkedWhole As Integer
Dim Remainder As Double
YearsWorkedWhole = CInt(Me.txtYearsWorked)
Remainder = Me.txtYearsWorked - YearsWorkedWhole
If Remainder = 0 Then
DoCmd.OpenForm "frmLengthOfEmploymentReminder"
End If
This works perfectly for 2000, 2001, 2002, but it doesn't work for 1999, 1998, etc.
For example
If txtJobStartDate = 24/09/00 Then txtYearsWorked = 3,
but if txtJobStartDate = 24/09/99 Then txtYearsWorked = 4.0027397260274 instead of 4.
The problem is the extra day in a leap year.
e.g. If JobStartDate = 24/09/00, then the number of days worked is 1095 days, which is divisible by 365 (=3).
But, If JobStartDate = 24/09/99, then the number of days worked is 1461 and not 1460 (as the year 2000 was a leap year). 1461 is not divisible by 365.
Any ideas on how to get around this? My head hurts.