Calculation field in Form

AbeA

Registered User.
Local time
Today, 11:58
Joined
Dec 21, 2006
Messages
28
Hi guys.

Could someone tell me how I would go about adding a form field in my form that will automate a number based on two other form fields? To be specific, I have a form that requests Employees add in their arrival time and departure time for a particular job. For instance, If they add 4:00 PM for arrival and 7:00 PM for departure, I want my third field, Hours, to automatically display "3." How would I go about doing this?

Thank you for your help!
 
name your first fields something like txtArrival and txtDeparture.

Create a third text field which is unbound.

For the control source you will need to put this in:

=(DateDiff("n", txtArrival.Value, txtDeparture.Value) / 60)

This will not account for someone who starts on one day and finishes the next though.
 
Thank you odin! That worked perfectly. I have one quick question though. How can I limit the number of numbers listed in the Hours field? For instance, I put 3:00 PM as arrival and 4:20 PM as departure, and it lists 1.33333333333 as the hours. I just want to display 1.33. Thanks a ton.
 
=Format((DateDiff("n",[txtArrival].[Value],[txtDeparture].[Value])/60),"#.##")
 
Odin, thanks again, worked perfectly.

Here is my final question!

How would I be able to round the number to the nearest fourth of an hour?

For example: If I enter "4:30 PM" as arrival time, and "4:50 PM" as departure, it automatically lists ".33" as the hours. Although this is correct, we would like to format the number so that it rounds to the nearest fourth of an hour (in this case, 30 minutes or ".50")

So all numbers should end with either a .00, .25, .50, or .75.

Thank you!
 

Users who are viewing this thread

Back
Top Bottom