How to update a form using a combo box

G

Guest

I have a form called EmpPaySummary. The form is originally created from a
table called Payroll. This form contains EmpNo, EmpStatus (full-time or
part-time), Wage_Rate, HoursWorked, and Check_Amt. All of which are columns
in the Payroll table. The EmpNo, EmpStatus, Wage_Rate and check_Amt are text
boxes (that will be locked b/c they don't need to be udated by the user).
HoursWorked is a combo box because the user simply updates the hours worked
for each employee.

My goal is to have the user select the hours worked via the combo box and
then the check amount for each employee will be updated. I am having trouble
with this. I the hours worked combo box works however the form is not
updating the check_amt text box is not updating. I created a macro that is
run when the user updates the hoursworked combo box but I'm still having
trouble updating the check_amt field. the code for the macro is below.
Please, please help me.

UPDATE Payroll SET Payroll.Check_Amt = Payroll.Wage_Rate*Payroll.HoursWorked;
 
A

Al Camp

There's no need to "save" the CheckAmt value. Since you've already
captured HoursWorked and WageRate, you only need an unbound calculated
CheckAmount field on the form to diplay the CheckAmount.
= cboHoursWorked * WageRate

Don't save calculations in a table that can always be recalculated, "on
the fly", in any subsequent form, query, or report.

If you must save CheckAmt however... make CheckAmt a bound text control
with a ControlSource of CheckAmt from your table, and use the AfterUpdate
event of both cboHoursWorked and WageRate to fire this code...
CheckAmt = cboHoursWorked * WageRate
That way, if either value changes, CheckAmount will be updated properly to
reflect the new values.
 
G

Guest

HL,

You're running into trouble because you're trying to store a calculated
field. Search the forum for the many reasons why this is undesirable.
Simply calculate this value in a query as a calculated field.

Also, I'm confused by why you need a combo box for HoursWorked. Wouldn't a
simple textbox be sufficient?

Sprinks
 
G

Guest

HL,

I forgot to mention--to *display* the CheckAmt on your form, simply set a
textbox ControlSource to the expression:

=[Wage_Rate]*[HoursWorked]

Sprinks
 

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