Solved

Update a Field based off a Percent

Posted on 2011-09-30
7
268 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
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.

 

Author Comment

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

0
 
LVL 39

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

910 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

23 Experts available now in Live!

Get 1:1 Help Now