开发者

Store field value in a table field Access 2010

I have a problem I have a simple calculation carried out on a form =[subtotal]-[discount]+[delivery]

I then want to store the result in my order table 开发者_运维问答under the field TotalPrice I have hunted around google but can not find anything that helps me.

I know its not good to store field values in tables but it needs to be done.

Thanks in advance.

Just to be clear. [subtotal] [discount] and [delivery] are all text boxes on a form. there is then a box called [Total] what appears in the textbox called [total] is what I want to then store the field in my order table.


It would be better to create a query, and then have whomever/whatever needs that calculated value use the query instead of the table directly.

HOWEVER, you could create a trigger on the form on something like the OnCurrent event, and then have that trigger execute the following.

me.txtCalcField = me.subtotal - me.discount + me.delivery

However, that would fire any time you changed records. It might be slightly better to check if it's set first

if isnull me.txtCalcField then
    me.txtCalcField = me.subtotal - me.discount + me.delivery
endif

But then if its components values get reset, your value doesn't get updated. In which case, you could put triggers on those fields as well (AfterUpdate events perhaps).

OR

You could check the value's aren't different each time.

if isnull me.txtCalcField then
    if me.txtCalcField <> me.subtotal - me.discount + me.delivery then
        me.txtCalcField = me.subtotal - me.discount + me.delivery
    endif
endif

(which probably won't work properly with Reals, but might with Currency)

Of course, that's all assuming the only way the components of txtCalcField will be updated is through the form - forever.

It's all a dog's breakfast - in which case, I direct you back to my first statement - use a query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜