Calculated Fields on a Form

S

SteveH

I have a form with two fields. One is called hours and the second is called
labor rate. I have a third field called Labor Cost. When a user enters this
field, I would like it to default to Hours times Labor Rate. What is the best
way to accomplish this?

Thanks
 
J

John Spencer

Is labor Cost ALWAYS Hours*LaborRate? If so, then you should not store it in
the table at all. Just use the expression when you need the labor cost.

If you want to fill in labor cost control with a value as a default that you
might modify due to circumstances, you would use some VBA to run in the after
update event of the Hours and Labor Rate controls

If isNull(ME.[LaborCost]) or ME.[LaborCost] = 0 then
ME.[LaborCost] = Me.Hours * Me.[LaborRate]
End if


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
B

Beetle

First, you don't really specify what is in your table, but just
as a point of information this calculated value should *not*
be stored in the table. Your table should only have the fields
for the Hours and the LaborCost. The calculation should be
done on the fly. You could use a calculated field in a query
like;

Total: [Hours] * [LaborCost]

then use that query as the record source of your form.

Or, you could use a calculated control (text box) on your
form with a Control Source like;

=[Hours] * [LaborCost].
 
J

Jeff Boyce

Steve

To add to what other's have suggested, why bother having the user "enter
this field" (I assume you mean tab into it). If the calculation is to be
automatic, that control should probably be disabled and not a regular tab
stop. After all, you don't want the user to make changes to it, do you?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top