Solved

Update a Field based off a Percent

Posted on 2011-09-30
7
283 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
  • 5
7 Comments
 
LVL 18

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

807 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