以连续的形式引用正确的信息

时间:2012-10-07 13:51:41

标签: sql database vba ms-access

我在连续表格的每条记录的末尾都有一个按钮,它需要这样做:

Private Sub Update_Click()

Dim SellP As Double
Dim BuyP As Double
Dim Profit As Double

SellP = DLookup(SellPrice, Flips, [Current])
BuyP = DLookup(BuyPrice, Flips, [Current])

Profit = SellP - BuyP

Flips.Profit = Profit

End Sub

现在我知道这不是正确的代码,但我希望它会让你知道它需要做什么,基本上:

找到SalePrice,从SalePrice中找到BuyPrice,减去BuyPrice并将结果显示为Profit,然后在Profit字段中填入利润..

谢谢!

1 个答案:

答案 0 :(得分:2)

绑定表/查询的当前记录的列可直接在代码中使用 你可以写例如 Profit = SalePrice - BuyPrice如果这些字段都是绑定数据的一部分 然后,您可以在SalePrice-和BuyPrice-Textfields的“AfterUpdate”-Event中移动此代码,可能是这样的:

If IsNull(salePrice) Or IsNull(buyPrice) Then
    Profit = 0
Else
    Profit = salePrice - buyPrice
End If