Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff accrual calculation

Status
Not open for further replies.

DomFino

IS-IT--Management
Jul 9, 2003
278
US
I am trying to create a function that calculates the amount of accrued vacation and sick time a person has on the current date. For example there are 26 pay periods in a year. If the current date were 11/07/03 that would be pay period 23. Since an employee accrues 6.7667 hours of vac each pay period and 4.6167 hours sick time each pay period I need to be able to determine what they currently have available.

Below is a SHORT version of my attempt at the vacation calculation. There must be a better way. Right? Any suggestions are appreciated.

Code:
Public Function setavHrs()
Dim lTime

    If Nz(Me.annDate.Value) = "" Or Nz(Me.cat.Value) = "" Then
        Exit Function
    End If

    If Me.cat.Value = 2 Then
        lTime = DateDiff("d", Me.annDate.Value, Now()) / 14
        Select Case lTime
            Case Is = 1 
                Me.avHrs.Value = 6.7667
            Case Is = 2 
                Me.avHrs.Value = 13.5333
            Case Is = 3 
                Me.avHrs.Value = 20.3000
            Case Is = 4 
                Me.avHrs.Value = 27.0667
            Case Is = 5
                Me.avHrs.Value = 33.8333
            Case Is = 6 
                Me.avHrs.Value = 40.6000
            Case Is = 7 
                Me.avHrs.Value = 47.3667
‘ this would continue for up to 26 pay periods
        End Select
    End If
    
End Function
 
Just multiply 1Time time your hours per pay period like this:

Me.avHrs.Value = 1Time * 6.7667
 
tledwards,
Thanks for your suggestion. It is so simple yet effective. God only knows what I must have been thinking!
Thanks again, works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top