View Full Version : Calculate TimeDiff


Neo90815
09-06-2000, 09:25 AM
I need to calculate the time [Start] and [TimeEnd] and display the results in another field called [TimeDiff].

The code described below works perfectly but the code is in the Control Source of [TimeDiff] on the Form. So, when I call for it in Table or Query the results/vaule of [TimeDiff] would not display.
*************************************
= Format([DateTime] - 1 - [AckwldgTime], "Short Time")
*************************************

I probably have to declare a variable and assign the results of the calculated fields to it. Then send the value to [TimeDiff] field....But I don't know the code http://www.access-programmers.co.uk/ubb/frown.gif

Anyone has any suggestions? Would I need to create Crosstable Query just to do this simple calcuation?

Thanks a million in advance!

Neo

Jack Cowley
09-06-2000, 09:42 AM
Put this in the After Update of the TimeEnd field: Me![TimeDiff] = Format([DateTime] - 1 - [AckwldgTime], "Short Time"). Or put it into the last field in which you actually enter the last time value. Be sure and set the TimeDiff Control Source back to the field name in the table.

HTH,
Jack

Neo90815
09-06-2000, 11:04 AM
Thanks Jack,

It makes sense but it did not work, nothing happened. The [TimeEnd] value gets it value from another form called Calendar (this shoudn't make a difference does it?)

The calendar form has an ActiveX Calendar, users double click on ActiveX Calendar to select a date, and type to enter a time in another field called [Time],this Time Field sends its value to TimeEnd once user click Insert. Still should not make a diference does it?

So I tried put the code in Command Button Event "OnClick" in the Calendar Form. And I got "Compiler error: Type Mismatch" and it high lighted the "-" before the 1. What is that 1 or - ?

Format([DateTime] - 1 - [AckwldgTime], "Short Time")

How ever it will work, just want it to display the calcuated results with the format as coded (HR:Min) to TimeDiff field. And be able to pull it from Table/Query.

Thanks again Jack.

Neo90815
09-08-2000, 10:10 AM
Thanks for the tip!

I placed the code in the query and it works great!

****************************
TimeDiff: = Format([DateTime] - 1 - [AckwldgTime], "Short Time")
******************************

Thanks!