访问表单计算字段 [英] Access form calculated fields

查看:62
本文介绍了访问表单计算字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用访问表单,但是在尝试计算字段时遇到问题.我有三个文本框:

I am working with access forms, but I am having a problem when I try to calculate fields. I have three text box:

  1. 数量
  2. 价格
  3. 总计

当我在数量和价格字段中键入数字时,Total字段应填充QuantityPrices

When I type numbers in quantity and price field the Total field should get populated with the total of Quantity and Prices

我尝试了很多公式,例如:

I have tried a lot of formulas like:

=[Quantity]*[Price]

但是,当我将表单放入表单视图"时,什么也没有发生.在Total字段中,我得到#Error.

But nothing happens when I put the form in Form View. In the Total field I get #Error.

推荐答案

一种方法是进入更新后事件",最后输入一个文本框(假定此示例为价格),然后使用代码

One way to do it is to go into the After Update Event for whichever text box (assuming price for this example) is entered in last and then use the code

Private Sub Price_AfterUpdate()
If Forms!YourFormName!Price.Value Is Not Null Then
Forms!YourFormName!Total.Value = Forms!YourFormName!Quantity.Value * Forms!YourFormName!Price.Value
End If
End Sub

如果您想更加安全,则可以执行该代码,并且

If you wanted to be more safe, you could do that code AND

Private Sub Quantity_AfterUpdate()
If Forms!YourFormName!Quantity.Value Is Not Null Then
Forms!YourFormName!Total.Value = Forms!YourFormName!Quantity.Value * Forms!YourFormName!Price.Value
End If
End Sub

以防用户出现故障.

这篇关于访问表单计算字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆