AnsweredAssumed Answered

Auto-Updating calculation field

Question asked by david@elsupergrillo.com on May 28, 2012
Latest reply on May 31, 2012 by david@elsupergrillo.com

Apparently, there's no way to reply or comment on discussions in the archive. Using the information from the discussion at https://fmdev.filemaker.com/message/32518#32518, and the reference guide, I have created a calculation field to hold elapsed time since a record's creation. A time field, "TimeStart" is automatically entered upon record creation. A second, unstored calculation field, "CurrentTime" is defined as simply "Get ( CurrentTime )." Then the "TimeElapsed" field, also unstored calculation "Case( ( CurrentTime - TimeStart ) > 60; Round (((CurrentTime - TimeStart)/60) ; 0 ) & " minutes";"0 minutes"

)."

 

I have a script "ElapsedTimer" defined "Insert Calculated Result [Table::TimeElapsed], and another script "StartElapsedTimer" defined as "Install OnTimer Script ["ElapsedTimer"; Interval: 60]." This Install OnTimer script is assigned to the OnLayoutEnter script trigger for a layout which displays the TimeElapsed field. That field on the layout has been prevented from entry, but the ElapsedTimer script, when run, puts the cursor in the field anyway. If I uncheck "Go to target field" in the script's definition, it erases the field defined in the script. But there are a couple of problems with it: 1) if, after the script is run and the cursor is active in the field, the user doesn't click anywhere to remove the focus from the field, the script won't run again until the user does click somewhere else; 2) If, when the script runs, the user is actively typing somewhere on the layout, when the TimeElapsed field receives the focus, the typed data is sent to the TimeElapsed field, and the user gets an error because the field cannot receive the typed text.

 

Is there a better way to cause the TimeElapsed field to update every 60 seconds without the field receiving focus on the layout?

Outcomes