Solved

Afterupdate event of a field to calculate and populate another field

Posted on 2013-06-20
6
402 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

743 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

15 Experts available now in Live!

Get 1:1 Help Now