can't calculate flying hour. how to add 50:20+1:23=

  • Thread starter Thread starter khaled831
  • Start date Start date
K

khaled831

i want to make a log book for my flying hours. i made a database. but can't
insert the flying hour in the record. like, i flew 5:30+3:40+.......total
hour comes like 990:00. plz tell me how to sum my hours. office only allows
me time like AM or PM. but i need hour not time.
 
One solution is to log TO and LND times, then use the DateDiff function to
calculate elapsed time. Or, you can log elapsed time in hours and tenths
(i.e. 5:10= 5.2, 5:30=5.5, etc.) then use normal math functions to
add/subtract times.
 
If you have a form with the record source set to your table of times, you
could add a textbox to display your total hours, and in the afterupdate of
the form:

Private Sub Form_AfterUpdate()
SumofHrs
End Sub

which calls the sub:

Sub SumofHrs()

Dim myArray(2) 'array to hold hours and minutes
Dim pos As Integer 'need position of ":" for hrs -could be 1 digit or 2
Dim hrs As Integer
Dim mins As Integer
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String

On Error GoTo ErrorHandler

Set dbs = CurrentDb
strSQL = "SELECT tableofFlyingtime.YourTimeRecorded FROM
tableofFlyingtime"
Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
'I called the table "tableofFlyingTime", timefield in the table
"YourTimeRecorded"
'If the recordset is empty, exit.
If rst.EOF Then Exit Sub

With rst
Do Until .EOF
pos = InStr(1, !YourTimeRecorded, ":", 1)
myArray(1) = CInt(Left(![YourTimeRecorded], pos - 1))
myArray(2) = CInt(Mid(![YourTimeRecorded], pos + 1, 2))
hrs = hrs + myArray(1)
mins = mins + myArray(2)
.MoveNext
Loop
End With
hrs = hrs + Int(mins / 60)
mins = mins Mod 60
Me.txtsum = hrs & "hrs and " & mins & "minutes." 'textbox to display
total
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
Exit Sub

ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub

HTH
Damon
 
Back
Top