- Local time
- Yesterday, 22:57
- Joined
- Feb 28, 2001
- Messages
- 29,976
@jpl458 - you are tripping over the difference between computation and presentation. You also did the computation backwards. Here is the basic VBA computation ...
Elapsed times always involve taking the larger time minus the smaller time, and for Access, any time after 30-Dec-1899 increases as the date gets later. The above sample would work correctly from VBA in the Form_Current event if [Durationtb] had a format property that would convert time to whatever units you wanted. You could also do this in VBA without formatting in the control properties.
If you wanted to not use VBA then use this expression as the .ControlSource of Me.Durationtb...
= Format( ( Me.endtime - Me.starttime ), "HH:NN" )
That would compute the difference for you without explicit VBA. It would be updated during each Form_Current event.
HOWEVER, if the difference exceeds 24 hours you will have issues because Access time routines do not allow conversion of times greater than one day using that particular method of formatting. You would have to "roll your own" formats for more than a day in minutes. If you wanted hours and minutes AND the hours could exceed 24, the best way is a two-step process. Is there a chance this difference could exceed 24 hours?
Code:
Me.Durationtb = Me.endtime - me.starttime
Elapsed times always involve taking the larger time minus the smaller time, and for Access, any time after 30-Dec-1899 increases as the date gets later. The above sample would work correctly from VBA in the Form_Current event if [Durationtb] had a format property that would convert time to whatever units you wanted. You could also do this in VBA without formatting in the control properties.
Code:
Me.Durationtb = Format( ( Me.endtime - Me.starttime ), "HH:NN" )
If you wanted to not use VBA then use this expression as the .ControlSource of Me.Durationtb...
= Format( ( Me.endtime - Me.starttime ), "HH:NN" )
That would compute the difference for you without explicit VBA. It would be updated during each Form_Current event.
HOWEVER, if the difference exceeds 24 hours you will have issues because Access time routines do not allow conversion of times greater than one day using that particular method of formatting. You would have to "roll your own" formats for more than a day in minutes. If you wanted hours and minutes AND the hours could exceed 24, the best way is a two-step process. Is there a chance this difference could exceed 24 hours?