473,573 Members | 4,141 Online

# Calculating hours and minutes

3 New Member
I really like the site so far and this is my first post. I have looked through some of the archives with no luck. I have also read the posting guidelines and will do my best to be clear and accurate with my problem. I am working with Access 2k / Win 2k. I have some experience and must have this figured out before Aug1.

What i am tasked with is to modify an existing process that calculates the hours and minutes worked, which is entered on a form using controls bound to fields in a table with simple functions running the calculations.
The initial process had 7 text boxes for data entry.
Each control had both hours and minutes entered, example: 7.2, and called the function
Expand|Select|Wrap|Line Numbers
2. 'Dim ri, pfh, tth, pht, ht, postht, at, th As Variant
3.
4. 'ri = Forms![attorney statements]![releasee interview]
5. 'pfh = Forms![attorney statements]![prep for hrg]
6. 'tth = Forms![attorney statements]![travel to hrg]
7. 'pht = Forms![attorney statements]![pre hrg time]
8. 'ht = Forms![attorney statements]![hear time]
9. 'postht = Forms![attorney statements]![post hrg time]
10. 'at = Forms![attorney statements]![appeals time]
11. 'th = Forms![Attorney Statements]![total hours]
12.
13. 'th = ri + pfh + tth + pht + ht + postht + at
14.
15. 'Forms![attorney statements]![total hours] = th
16. End Function
on the exit property.

In the function, th = "total hours" and this control holds the result. The data entered comes from a form sent in from clients with the time they spent working on a case. This time is currently being converted by the person entering the data using a conversion table showing,
"1 = 2 all the way up to 60 = 100". An example on the sheet states, Total hours worked is 6hrs 20 min. The conversion will be 6.33. This confused me!!

They want to get rid of this conversion and just calculate the time by 60 instead of 100.
What I did is separate the hours from the min by creating 7 new controls to capture the minutes. The new form now has the original control "releasee interview" for the hours worked entry and the new control "Rel Interview Min" for the minutes worked capture. I followed this process for all 7 controls. I am no loner calling the hours function and created the routine,
Expand|Select|Wrap|Line Numbers
1.
2. Private Sub Rel_Interview_Min_AfterUpdate()
3. Dim ri, rim, rit  As Long
4.
5. ri = Forms![attorney statements]![releasee interview]
6. rim = Forms![attorney statements]![Rel Interview Min]
7. 'rit = Forms![attorney statements]![Rel Interview Total]
8.
9. rit = ri * 60 + rim
10. Forms![attorney statements]![Rel Interview Total] = rit
11. End Sub
to run in the AfterUpdate property of all of the minute controls.
Then I created seven controls that will not be visible, using the same naming style, except they end with total to hold this result.
My thinking is to change everything into minutes to be held in the Total min controls and then in the "total hours" control, in the "On Enter" property run this routine:
Expand|Select|Wrap|Line Numbers
1.  Private Sub total_hours_Enter()
2. Dim rit, pfht, ttht, phtt, htt, pohtt, att, th As Long
3.
4. rit = Forms![attorney statements]![Rel Interview Total]
5. pfht = Forms![attorney statements]![Prep for Hrg Total]
6. ttht = Forms![attorney statements]![Travel to Hrg Total]
7. phtt = Forms![attorney statements]![Pre Hrg Time total]
8. htt = Forms![attorney statements]![Hrg Time Total]
9. pohtt = Forms![attorney statements]![Post Hrg Time Total]
10. att = Forms![attorney statements]![Appeals Time Total]
11. 'th = Forms![attorney statements]![total hours]
12.
13. th = rit + pfht + ttht + phtt + htt + pohtt + att
14. Forms![attorney statements]![total hours] = th
15. End Sub
, to get the total minutes,

and in the "On Exit" property run this routine:
Expand|Select|Wrap|Line Numbers
1.  Private Sub total_hours_Exit(Cancel As Integer)
2.
3. Dim th As Long
4.
5. 'th = Forms![attorney statements]![total hours]
6.
7. th = Forms![attorney statements]![total hours]
8.
9. Forms![attorney statements]![total hours] = th / 60
10. End Sub
, to get back to hours and Minutes.

I hope what i am trying to do is clear, i can't seem to figure out how to keep the minutes under 60, and stop the division keeping the remainder.

Any help is greatly appreciated
Aug 16 '07 #1
6 4230
Scott Price
1,384 Recognized Expert Top Contributor

http://office.microsoft.com/en-us/ac...CL100570041033

Regards,
Scott
Aug 16 '07 #2
richbneal
3 New Member
Thanks Scott - I am leaning toward data type and the final formatting of data holding up progress. I will keep trying. Thanks for the link.
Aug 17 '07 #3
Stwange
126 Recognized Expert New Member
6.33 is six and one third hours, which is 6h20.
A simpler way to do this would be to use the existing system, and then add another step to convert it (as the decimal is also a percentage of whole, so multiply it by 60)
Eg. (I haven't test this, but if it doesn't work it should give you an idea)
Private Function convertHours(by val hour as Single) as Single
dim pos as integer
pos = instr(cstr(hour ),".")
if pos <> 0 then
dim fraction as single
fraction = CSng("0" & mid\$(CStr(hour) ,pos))
fraction = (fraction / 100) * 60
convertHours = CSng(mid\$(CStr( hour),1,pos - 1)) + fraction
end if
End Function

Good Luck. And by the way, It's already past August 1st?
Aug 17 '07 #4
richbneal
3 New Member
6.33 is six and one third hours, which is 6h20.
A simpler way to do this would be to use the existing system, and then add another step to convert it (as the decimal is also a percentage of whole, so multiply it by 60)
Eg. (I haven't test this, but if it doesn't work it should give you an idea)
Private Function convertHours(by val hour as Single) as Single
dim pos as integer
pos = instr(cstr(hour ),".")
if pos <> 0 then
dim fraction as single
fraction = CSng("0" & mid\$(CStr(hour) ,pos))
fraction = (fraction / 100) * 60
convertHours = CSng(mid\$(CStr( hour),1,pos - 1)) + fraction
end if
End Function

Good Luck. And by the way, It's already past August 1st?
This looks very positive, thank you very much. I guess I am more stressed than i thought. Sept 1st is what i wanted to write.
Aug 17 '07 #5
missinglinq
3,532 Recognized Expert Specialist
Well, duh! From looking at your code, you're apparently working with lawyers! That's enough to stress out a Buddist Monk on Valium!

Welcome to TheScripts!

Linq ;0)>
Aug 17 '07 #6
Scott Price
1,384 Recognized Expert Top Contributor
Well, duh! From looking at your code, you're apparently working with lawyers! That's enough to stress out a Buddist Monk on Valium!

Welcome to TheScripts!

Linq ;0)>
Thanks, Linq!! Made me laugh :-)

I was thinking that lawyers who like to double bill hours probably wouldn't want to implement a system more like a time-clock which would limit them from being able to double bill, but would be MUCH simpler to calculate elapsed time with since the functionality to do so is already built into Access... Didn't want to point out that earlier, though LOL

Regards,
Scott
Aug 17 '07 #7