View Full Version : Can a default table value be a calculated value?


pdbowling
06-23-2005, 09:28 AM
Hi all,
I have a table...

Amount........Wholesale...........Commission

Lots of other columns but they don't come in to play.

When an Amount is entered, can Wholesale and Commission auto populate with Amount*.9 and Amount *.1 using default values in the table definition? I couldn't quite get the expression builder to understand.

If it can't, how should I get it to work? Forms are OK. As is code.
Thanks
PB

Pat Hartman
06-23-2005, 02:52 PM
There is no need, nor is it correct to store calculated values. Calculate the two fields in your query.

neileg
06-24-2005, 01:30 AM
Pat is correct if your commission rate is always the same. However, I believe you're wanting a default value of 10%, which you may overwrite. Use a bit of vba code in the after update event of your Amount text box. Like this:Private Sub txtAmount_AfterUpdate()
txtWholesale = txtAmount * 0.9
txtCommission = txtAmount - txtWholesale
End Sub
If you want the commission to autocalculate after you amend the wholesale price, add this to the after update event of txtWholesale:
Private Sub txtWholesale_AfterUpdate()
txtCommission = txtAmount - txtWholesale
End Sub
Of course you may want to swap this around so that you enter the commission and the wholesale is calculated, or even have both at the same time. See the attached sample.