在表字段中存储字段值 Access 2010

发布于 2024-11-01 05:34:36 字数 281 浏览 3 评论 0原文

我有一个问题,我在表格上进行了一个简单的计算 =[subtotal]-[discount]+[delivery]

然后我想将结果存储在我的订单表中的 TotalPrice 字段下 我在谷歌上搜索过,但找不到任何对我有帮助的东西。

我知道将字段值存储在表中不好,但需要这样做。

提前致谢。

只是要明确一点。 [小计] [折扣] 和 [送货] 都是表单上的文本框。然后有一个名为 [Total] 的框,出现在名为 [total] 的文本框中,这就是我想要将该字段存储在我的订单表中的内容。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长梦不多时 2024-11-08 05:34:37

最好创建一个查询,然后让需要计算值的任何人/任何东西使用查询而不是直接使用表。

但是,您可以在表单上创建一个触发器(例如 OnCurrent 事件),然后让该触发器执行以下操作。

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

但是,每当您更改记录时,都会触发该操作。首先检查它是否已设置可能会稍微好一些

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

,但是如果其组件值被重置,您的值不会更新。在这种情况下,您也可以在这些字段上放置触发器(也许是 AfterUpdate 事件)。

或者

您可以检查每次的值是否不同。

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

(对于实数可能无法正常工作,但对于货币可能无法正常工作)

当然,这一切都假设 txtCalcField 组件更新的唯一方式是通过表单 - 永远。

这都是狗的早餐 - 在这种情况下,我引导您回到我的第一个陈述 - 使用查询。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文