I need VBA Code to to figure payroll hours and pay amount_now to the nearest 15 minutes

Original Question: I have a Work Hours Table and I want to enter A [StartTime]  and and an [EndTime] and it will go over 24hours.  I need code to figures hours elapsed to the nearest half hour, and I need to be able to preform an expression to figure the pay, like [Hours]*[PayRate] to yeaild me total pay.  I would like this to be Public Function and useable in multiple Reports.  I have found a code to yeild me the Total Hours but it formats it in Hours:Minutes and I can't figure how to multiply it by my [PayRate].  I have attached the code I found.
Using, Access 2007

Now It seems I need it to be to the nearest 15 min,  I've attached the code that worked to the nearest 30 minutes.
Public Function ElapsedHours(StartTime, EndTime)
    'figures the number of hours elapsed between the two dates
    
    Dim mMins As Integer
    Dim mHours As Double
    Dim mRemainder As Double
    
    mMins = DateDiff("n", StartTime, EndTime)
 
    mHours = Int(mMins / 60)
    mRemainder = (mMins) - (mHours * 60)
    If mRemainder >= 45 Then
        mHours = mHours + 1
    ElseIf mRemainder >= 30 Then
        mHours = mHours + 0.5
    ElseIf mRemainder >= 15 Then
        mHours = mHours + 0.5
    End If
    
    ElapsedHours = mHours
    
End Function

Open in new window

bdgbrickAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RyanProject Engineer, ElectricalCommented:
define your parameters in your function explicitly.

StartTime as date, EndTime as Date.

In your query, the time should be a date/time format, and it'll workout pretty easily. Theres a problem if the dates cross over midnight unless you have a date included with your time.

If all you're wanting is this code modded to 15min then...
Public Function ElapsedHours(StartTime, EndTime)
    'figures the number of hours elapsed between the two dates
    const FACTOR = 15
    Dim mMins As Integer
    
    mMins = DateDiff("n", StartTime, EndTime)
    
    ElapsedHours = round(mMins/FACTOR,0) * FACTOR /60
 
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bdgbrickAuthor Commented:
Great Thanks so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.