Solved

Afterupdate event of a field to calculate and populate another field

Posted on 2013-06-20
6
409 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2010 Form - Turn Updating On - Off 31 98
SUBFORM on ACCESS 2013 8 36
ISeries Remote Location Route entry 2 28
Tabbed form question 5 20
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

751 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