Solved

Afterupdate event of a field to calculate and populate another field

Posted on 2013-06-20
6
410 Views
Last Modified: 2013-06-21
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
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:pjevin
ID: 39262853
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
 

Author Comment

by:SteveL13
ID: 39262895
The fields are on a form, not a report.  I'm using the afterupdate event of the field, "Me.txtProfPercentOther".
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 39262914
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
Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

 
LVL 58
ID: 39263079
<<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
 
LVL 58
ID: 39263088
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
 
LVL 31

Accepted Solution

by:
Helen Feddema earned 500 total points
ID: 39263103
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question