Solved

Afterupdate event of a field to calculate and populate another field

Posted on 2013-06-20
6
404 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 57
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 57
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now