基于周年日的假期计算

时间:2014-07-15 20:40:22

标签: function ms-access if-statement calculated-field

规则是在您工作的第一年之后,根据您的周年日,您将获得40个小时。 (例如,我于2011年12月5日被聘用,我在2012年12月5日度假40小时。)

然后每年都会滚动到日历年。因此,使用我的上述示例,我需要在2012年12月5日至2012年12月31日期间使用我的40小时,因为在2013年1月1日我的四十岁开始。

在三年(2014年1月1日),日历日期,我会得到80小时。

在10年的日历日期,它会变为120.我正在使用的代码如下,但它没有正确显示...

Function calcVacEarned(asOfDate As Date, HireDate As Date)
    Dim anniversary As Boolean
    Dim yos As Integer
    anniversary = False
    yos = Year(asOfDate) - Year(HireDate)

    If Month(HireDate) = Month(asOfDate) And (yos = 1) Then
      If Day(HireDate) <= Day(asOfDate) Then
        anniversary = True
    End If
    ElseIf Month(HireDate) < Month(asOfDate) And (yos = 1) Then
        anniversary = True
    End If

    If anniversary Then
        calcVacEarned = 40
    Else
        Select Case yos
          Case Is > 10
            calcVacEarned = 120
          Case Is > 3
            calcVacEarned = 80
          Case Is > 1
            calcVacEarned = 40
          Case Else
            calcVacEarned = 0
        End Select
    End If

End Function

我的公司每天使用它来全面计算小时数,可以使用一些帮助。提前谢谢!

1 个答案:

答案 0 :(得分:0)

假设您正在为yos返回正确的整数:

If anniversary Then
    Select Case yos
    Case 1
        MsgBox "You actually get vacation"
    Case 2
        MsgBox "OP said nothing regarding 2 years!"
    Case 3
        MsgBox "You get 80 hours!"
    Case 10
        MsgBox "You get 120 hours!"
    End Select
End If
相关问题