Two After Update Events to calcalate?

S

Steve Stad

I have these two 'AfterUpdate' events to calculate Emp_Prod_Alloc1. They
work fine separately (i.e., one or the other in the program) but shouldn't
they also work simultaneously - i.e., shouldn't I be able to have them both
in the program so either one will update the Emp_Prod_Alloc1 percentage.

Private Sub EMP_ANNUAL_HOURS_AfterUpdate()
Emp_Prod_Alloc1 = Emp_Prod_hrs1 / EMP_ANNUAL_HOURS
End Sub

Private Sub Prod1_Hrs_AfterUpdate()
Emp_Prod_Alloc1 = Prod1_Hrs / EMP_ANNUAL_HOURS
End Sub
 
D

Daryl S

Steve -

Yes, you can have multiple procedures updating the same data. Since your
formulas are different, it makes me wonder what should be in Emp_Prod_Alloc1.
I don't see any checking to make sure EMP_ANNUAL_HOURS is not zero - you
will get a run-time error if you try to divide by zero.

Is this a variable you are calculating? If these are controls on the form,
then it would usually be coded like this:
Me.Emp_Prod_Alloc1 = Me.Emp_Prod_hrs1 / Me.EMP_ANNUAL_HOURS

If you are not getting what you want, please tell us if you are getting any
errors. If the results are not what you expect, provide some examples so we
can help more.
 
S

Steve Stad

Thanks Daryl,

I changed the formula(s) to the below to account for any 'nulls'.
Emp_Prod_Alloc1 = (Nz([Emp_Prod_hrs1], 0)) / (Nz([EMP_ANNUAL_HOURS], 0))

I kept this one the same and it still works OK so far.
Private Sub Prod1_Hrs_AfterUpdate()
Emp_Prod_Alloc1 = Prod1_Hrs / EMP_ANNUAL_HOURS
End Sub
 
D

Daryl S

Steve -

If EMP_ANNUAL_HOURS can ever be zero, you will need to code for that, too,
since division by zero will give you a run time error.

--
Daryl S


Steve Stad said:
Thanks Daryl,

I changed the formula(s) to the below to account for any 'nulls'.
Emp_Prod_Alloc1 = (Nz([Emp_Prod_hrs1], 0)) / (Nz([EMP_ANNUAL_HOURS], 0))

I kept this one the same and it still works OK so far.
Private Sub Prod1_Hrs_AfterUpdate()
Emp_Prod_Alloc1 = Prod1_Hrs / EMP_ANNUAL_HOURS
End Sub

Daryl S said:
Steve -

Yes, you can have multiple procedures updating the same data. Since your
formulas are different, it makes me wonder what should be in Emp_Prod_Alloc1.
I don't see any checking to make sure EMP_ANNUAL_HOURS is not zero - you
will get a run-time error if you try to divide by zero.

Is this a variable you are calculating? If these are controls on the form,
then it would usually be coded like this:
Me.Emp_Prod_Alloc1 = Me.Emp_Prod_hrs1 / Me.EMP_ANNUAL_HOURS

If you are not getting what you want, please tell us if you are getting any
errors. If the results are not what you expect, provide some examples so we
can help more.
 

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