Bob P
Bob P

Reputation: 237

Referencing the right information in a continuous form

I have a button at the end of each record on a continuous form and it needs to do this:

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

Now I know this isn't the correct code but I hope it will give you an idea of what it needs to do, essentially:

Find the SalePrice, find the BuyPrice, minus the BuyPrice from the SalePrice and make the result Profit, then populate the Profit field with profit..

Thanks!

Upvotes: 0

Views: 79

Answers (1)

KekuSemau
KekuSemau

Reputation: 6852

The columns of the current record of the bound table/query are directly available in the code.
You can just write e.g. Profit = SalePrice - BuyPrice if these fields are all part of the bound data.
You might then move this code in the "AfterUpdate"-Event of both the SalePrice- and the BuyPrice-Textfields, maybe like this:

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

Upvotes: 2

Related Questions