What is the name of the event that triggers the execution of a formula?

PepeGallo

Registered User.
Local time
Today, 12:30
Joined
May 2, 2008
Messages
14
Hi folks!

I have a textbox that gets the result of a subtotal calculation and I want another text box get the result of the first textbox plus the tax, but besides that, I want that result to be stored in the Total field of that form's underlying table. How can I do this?

Maybe a solution to this is by triggering this action when an event happens, so I think that the perfect event to do this is when the formula in the control source property of the subtotal textbox is executed, but I don't know what is the name of that event and which object it applies. Thank you
 
A simpler method would be to place a command button on your form. Label it "Calculate".

In the code for the button, enter the math you wish to perform.
Example:
If [Subtotal] > 0 then
[Tax] = ([Text2]*.07) If the tax is 7 percent
[Total] = ([Subtotal]+[Tax])
Endif
 
Yes, but I would like to do it without a button, just automatically, so don't anybody knows the name of the event I have to use ?
 
Well there are plenty of events. For example, it could be on LostFocus from one of the fields where you enter the data to produce the result of the calculation.However, a problem you can encounter is setting the value of your total field can occur before the textboxes do the calculations and that will mean the value of [Total] will be set to null.

Sometimes it is better do it with calculated fields in a query.

Or if you have a close button or label for your form or similar to move to next record or another form etc you have that run the setvalue of your field Total becasue each of those will be done after text boxes have their value.
 
Unless the reason and circumstance of such can be stated clearly then there should be no reason to store the calculated value.

Regards,
Chris.
 
;you dont need an event

have one box (say goodsvalue) with a value

have another box (say taxrate) with a tax rate

the calculation box contains the formula

= [goodsvalue] * [taxrate]
{access shouild put the square brackets in automatically}

you dont need any programming to do this
 
Pepe:
There is no specific pre-existing event that will do what you are describing. The reason for this is very simple, you have to specifically state which text box is added, subtracted divided etc. to another text box in order to get the results you want..

You must create your own event to do what you want. There are several excellent tips on how to do this listed above.
 
Trigers execution of formula

I don't know whether you are looking for something similar to the one given below. This is taken from MS-Access Help, giving an example of the usage of Eval() Function.

The next example triggers a Click event as if the user had clicked a button on a form. If the value of the button's OnClick property begins with an equal sign (=), signifying that it is the name of a function, the Eval function calls the function, which is equivalent to triggering the Click event. If the value doesn't begin with an equal sign, then the value must name a macro. The RunMacro method of the DoCmd object runs the named macro.

Dim ctl As Control, varTemp As Variant

Set ctl = Forms!Contacts!HelpButton
If (Left(ctl.OnClick, 1) = "=") Then
varTemp = Eval(Mid(ctl.OnClick,2))
Else
DoCmd.RunMacro ctl.OnClick
End If
 

Users who are viewing this thread

Back
Top Bottom