Code to Calculate Field in Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My time sheets are really beginning to take shape. I now have one last
question. If this question is answered, the form will be perfect. The form
has two time fields:
[ActualStart] and [ActualEnd]

I created a field called [TotalHrs] which calculates the number of hours
worked.

What I now need is a field which will calculate:

[TotalHrs]*[HrlyRate] or $100, whichever is greater.

Can you help me with the code for this new field.

I love this site. It has helped me tremendously. Thank you
 
R Marko said:
My time sheets are really beginning to take shape. I now have one
last question. If this question is answered, the form will be
perfect. The form has two time fields:
[ActualStart] and [ActualEnd]

I created a field called [TotalHrs] which calculates the number of
hours worked.

What I now need is a field which will calculate:

[TotalHrs]*[HrlyRate] or $100, whichever is greater.

Can you help me with the code for this new field.

An expression to calculate that would be something like this:

=IIf([TotalHrs]*[HrlyRate] > 100, [TotalHrs]*[HrlyRate], 100)

But I'm not sure whether you should be using a calculated control for
this or not, because I don't know what is stored in your table and what
isn't. If [ActualStart] and [ActualEnd] are stored in your table, and
if [TotalHours] is calculated directly from those fields, then
[TotalHours] doesn't need to be stored. And if [HrlyRate] is stored in
the table, then your final field is always calculable from these three
fields and need not be stored anywhere. Otherwise, you may need to
calculate the value and store it in the table by way of a bound control.
 
You're a God! It all works great.

Dirk Goldgar said:
R Marko said:
My time sheets are really beginning to take shape. I now have one
last question. If this question is answered, the form will be
perfect. The form has two time fields:
[ActualStart] and [ActualEnd]

I created a field called [TotalHrs] which calculates the number of
hours worked.

What I now need is a field which will calculate:

[TotalHrs]*[HrlyRate] or $100, whichever is greater.

Can you help me with the code for this new field.

An expression to calculate that would be something like this:

=IIf([TotalHrs]*[HrlyRate] > 100, [TotalHrs]*[HrlyRate], 100)

But I'm not sure whether you should be using a calculated control for
this or not, because I don't know what is stored in your table and what
isn't. If [ActualStart] and [ActualEnd] are stored in your table, and
if [TotalHours] is calculated directly from those fields, then
[TotalHours] doesn't need to be stored. And if [HrlyRate] is stored in
the table, then your final field is always calculable from these three
fields and need not be stored anywhere. Otherwise, you may need to
calculate the value and store it in the table by way of a bound control.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top