Access form calculated fields

2019-09-08 15:13发布

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

  1. Quantity
  2. Price
  3. Total

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]

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

1条回答
萌系小妹纸
2楼-- · 2019-09-08 15:47

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

Incase the users go out of order.

查看更多
登录 后发表回答