我的Access数据库中有一个表单根据我的公司政策计算了Vacation。根据您的周年纪念日,您获得40个小时后,您的第一年就业规则。 (例如,我于2012年6月9日被聘用,我在2013年6月9日度假40小时。)
然后每年都会滚动到日历年。因此,使用我的上述示例,我需要在2013年6月9日至2013年12月31日期间使用我的40小时,否则我将失去它们,因为2014年1月1日我收到了40小时。
三年,日历日期,我会得到80小时。 2016年1月1日,我得到80个小时。
10年,日历日期,它变为120.我一直在使用的代码继续从周年纪念日开始:
Function calcVacEarned(asOfDate As Date, HireDate As Date)
Dim yos As Single
Dim curryear As Integer
Dim hireYear As Integer
curryear = Year(asOfDate)
hireYear = Year(HireDate)
yos = (asOfDate - HireDate) / 365.25
If yos >= 1 Then
Select Case yos
Case Is > 10
calcVacEarned = 120
Case Is > 3
calcVacEarned = 80
Case Is > 1
calcVacEarned = 40
Case Else
calcVacEarned = 0
End Select
Else
If hireYear >= curryear Then
calcVacEarned = "0"
Else
If DateSerial(curryear, Month(HireDate), Day(HireDate)) = asOfDate Then
calcVacEarned = "40"
Else
calcVacEarned = "0"
End If
End If
End If
End Function
我的公司每天使用它来全面计算小时数,可以使用一些帮助。提前谢谢!
答案 0 :(得分:0)
我希望我明白你在问什么。这是:
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