Solved How to set formula as default value? (1 Viewer)

yunhsuan

Member
Local time
Today, 13:35
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

  • Database4.accdb
    628 KB · Views: 412

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:35
Joined
Oct 29, 2018
Messages
21,358
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:

June7

AWF VIP
Local time
Yesterday, 21:35
Joined
Mar 9, 2014
Messages
5,424
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:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:35
Joined
Feb 28, 2001
Messages
27,001
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.
 

yunhsuan

Member
Local time
Today, 13:35
Joined
Sep 10, 2021
Messages
54
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?
 

yunhsuan

Member
Local time
Today, 13:35
Joined
Sep 10, 2021
Messages
54
Thanks for everyone's suggestions.
I have known how to solve my problem.
 

Users who are viewing this thread

Top Bottom