Word is definitely not the best tool for the job. However, using the Legacy
FormFields available in the Controls section of the Developer tab, and a
macro containing the following code run on exit from the formfield into
which the finish time is entered, the duration between the start and the
finish times will be calculated and appear in the Duration formfield.
' a Macro to calculate the elapsed time for formfields with Date format of
HH:mm
' Macro created 16 May 1999 by Doug Robbins - Word MVP
'
Dim Start as String, Finish as String
Dim StartHour as Long, StartMinutes as Long, StartTimeMinutes as Long
Dim FinishHour as Long, FinishMinutes as Long FinishTimeMinutes as Long
Dim Elapsed Minutes as Long, Elapsed Hours as Long
Start = ActiveDocument.FormFields("Start").Result
StartHour = Val(Left(Start, 2))
StartMinutes = Val(Right(Start, 2))
StartTimeMinutes = StartHour * 60 + StartMinutes
Finish = ActiveDocument.FormFields("Finish").Result
FinishHour = Val(Left(Finish, 2))
FinishMinutes = Val(Right(Finish, 2))
FinishTimeMinutes = FinishHour * 60 + FinishMinutes
ElapsedMinutes = FinishTimeMinutes - StartTimeMinutes
ElapsedHours = Int(ElapsedMinutes / 60)
ElapsedMinutes = ElapsedMinutes - ElapsedHours * 60
ActiveDocument.FormFields("Duration").Result = Str(ElapsedHours) & ":" &
Format(ElapsedMinutes, "00")
If I were creating a timesheet system that made use of Microsoft Office, I
would develop it in Access. Excel would be the next choice of application
and Word would be the last.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP