Solved How to set formula as default value?

yunhsuan

Member
Local time
Today, 13:50
Joined
Sep 10, 2021
Messages
54
I tried to set formula as default value.
I hope the taxes value can be changed according to two fields in the same table.
But it not works as expected.
Could any one help me?
Below is my access file.

Thanks for your suggestions.
 

Attachments

Hi. You may have unrealistic expectations with regards to the Default Value. It only applies to New Records. Take a look at the screenshot of your form below. The "new" record will get Taxes=40 because that's what the default value property does. What did you want to happen with the new record instead? Keep in mind, the new record will not have any value for Quantity and Unit Price yet.

1631548446134.png
 
Last edited:
Just calculate the tax when needed. Put the expression in ControlSource. If there is possibility tax rate could change, use code (macro or VBA) to save rate or result.
 
Last edited:
Default values go into records when they are first created. They are essentially static in nature, in that once the record is created, they do nothing else unless you reach in and change the field value. If your form's user changes values in a new record, the value for which the default was applied does not change unless the USER changes it, too. The most likely place to do what you want would be (perhaps) to put code in the LostFocus routines for the quantity and unitprice fields, and recompute in those places. Then have something in the Form_BeforeUpdate event routine perform the computation for you. If you tried to put a formula as the .ControlSource, you would find that you could not bind that directly to the record. There is no guaranteed static way to do this without a lot of work.
 
Just calculate the tax when needed. Put the expression in ControlSource. If there is possibility tax rate could change, use code (macro or VBA) to save rate or result.
Thanks for your reply!
I need tax rate could change.
But I don't know how to do. Can you tell me which function I can use? Or does any example let me refer to?
 
Thanks for everyone's suggestions.
I have known how to solve my problem.
 

Users who are viewing this thread

Back
Top Bottom