Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

Afterupdate event of a field to calculate and populate another field

I have this code in the afterupdate event of a field...

    Me.txtProfBreakdownInvestor.Value = (100 - Me.txtProfPercentOther.Value)

But txtProfBreakdownInvestor doesn't update with the calculation.

????
0
SteveL13
Asked:
SteveL13
1 Solution
 
pjevinCommented:
How are you updating that field?

http://msdn.microsoft.com/en-us/library/office/aa211226%28v=office.11%29.aspx

Notes:

    Changing data in a control by using Visual Basic or a macro containing the SetValue action doesn't trigger these events for the control. However, if you then move to another record or save the record, the form's AfterUpdate event does occur.

    The AfterUpdate event applies only to controls on a form, not controls on a report.

    This event does not apply to option buttons, check boxes, or toggle buttons in an option group. It applies only to the option group itself.
0
 
SteveL13Author Commented:
The fields are on a form, not a report.  I'm using the afterupdate event of the field, "Me.txtProfPercentOther".
0
 
pdebaetsCommented:
It is likely that you will also need that calculation in the Form OnCurrent event procedure so that the calculated value is displayed when the first record is loaded and each time you go to a different record.
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<ut txtProfBreakdownInvestor doesn't update with the calculation.>>

 Confirm the code is hooked up to the control event:

1. Right click on the control that should trigger the code.

2. Select properties.

3. On the event tab, make sure the AfterUpdate event reads "[Event procedure]".

4.  Click the builder button (...) off to the right.  

  The VBA editor should open and bring you to the code.   If it brings you to a blank procedure, this is where you need your update statement.

  The connection between VBA and a Access object can break (most often this happens when you rename a control)

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
BTW,  you can also tell if you have un-attached code in the VBA by selecting "(general)" in the combo on the left.

 Then in the combo on the right, hit the drop down.  You should only see non-event procedures here that you've written.

  If you see any others, it's orphaned code.

Jim.
0
 
Helen FeddemaCommented:
You could just use a calculated control source expression, if you don't need to save the calculated value to the field, or (if you have a recent version of Access), create a calculated field in the table.  If you have an older version of Access, it is generally better to do calculations in a query, not saving the results to a field, as they can become outdated.  So you could do the calcs in the form's record source query, and put the calculated query field on the form instead of a table field.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now