Solved

Update a Field based off a Percent

Posted on 2011-09-30
7
256 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:pdvsa
Comment Utility
I mean me.CalcAmount = me.Amount

0
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thhe  Current Event could possibly be simplified... if you see it please let me know.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

762 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

12 Experts available now in Live!

Get 1:1 Help Now