Solved

Update a Field based off a Percent

Posted on 2011-09-30
7
289 Views
Last Modified: 2013-11-28
Experts,

I have this form with a field control source named [Percent]
I also have a field control source named [Amount]
I also have an unbound field with =[Percent]*DLookUp("[Amount]","tblLetterOfCredit","[LetterOfCreditID] = " & [Forms]![frmLetterOfCredit_Cont]![LetterOfCreditID])

I need the value of this amount in the unbound field (named PctAmount) to be updated to the other field [Amount].

I want to capture the calculated amount and put it in the field [Amount] so it will be in the table.

please see pic

untitled.JPG
0
Comment
Question by:pdvsa
[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
  • 5
7 Comments
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 36894985
I am still confused with your question.  Is the blank box supposed to end up as the calculated result?
And, is the original Amount and the new calculated amount both stored in the table?

one option:
Use a bound field instead of the unbound field.  Use the Expression builder to enter your formula in the AfterUpdate event on both the Percent and the Amount fields to calculate the NewAmount field as defined.
This will result in the new amount field being calculated whenever the percent or amount number changes and in being stored in the new field name of your table.
0
 

Author Comment

by:pdvsa
ID: 36895000
DoDahD:
<Is the blank box supposed to end up as the calculated result?
Yes
<And, is the original Amount and the new calculated amount both stored in the table?
I do have a field called [Amount] in the table.  I also have a field called [Percent]

Does that change anything?
0
 

Author Comment

by:pdvsa
ID: 36895013
What formula would I use?  
I tried something like

AfterUpdate:
me.Percent = Me.Amount

but it said that it cant assign a value to this field.  
0
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!

 

Author Comment

by:pdvsa
ID: 36895015
I mean me.CalcAmount = me.Amount

0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 36895603
Be careful with names in your form. May be better to add 1(2,3 etc) to field Amount if your table have also such field. Check also left and right sides of equation.
If field in table (which should be updated) is Amount, give name of field in form -Amount1. Equation will be:
Me.Amount1 = Me.PctAmount
Try also:
Me.Amount1 = Cdbl(Me.PctAmount)
0
 

Author Comment

by:pdvsa
ID: 36897322
ok that helped out a lot.  

The Me.Amount1 = Me.PctAmount ==> was not the solution
       Me.Amount1 = Cdbl(Me.PctAmount)===> was the solution

I finally ended up with this:
(pay attention to the current event.  I am not completely sure if there is something blatently wrong with it but it seems to work.  I had to add the If statement and I am not a programmer for certain.

Option Compare Database

Private Sub CalcAmount_Change()

    Me.Amount1 = CDbl(Me.CalcAmount)
   
End Sub

Private Sub Form_Current()

    If Nz(Me.Amount1, 0) = 0 Then
        Me.Amount1 = Me.CalcAmount
     Else
     
    Me.Amount1 = CDbl(Me.CalcAmount)
   
    End If
   
End Sub

Private Sub txtPercent_AfterUpdate()

    Me.Amount1 = CDbl(Me.CalcAmount)
   
End Sub
0
 

Author Comment

by:pdvsa
ID: 36897329
Thhe  Current Event could possibly be simplified... if you see it please let me know.
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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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 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 …

738 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