Originally Posted by
shod90
I want to make a button that changes all the profit percentage for all records based on Sell price and Buy Price...
Originally Posted by
shod90
PercentValue = SellPrice * (PercentValue / 100)
Where is BuyPrice? Currently you replace profit percentage with profit value!
And easier and faster would be an update query.
Create a saved query like
Code:
uqUpdateMyTable = UPDATE tblMyTable SET PercentValue = 100*((SellPrice - BuyPrice)/BuyPrice)
Create a procedure like
Code:
Public Sub UpdateTable()
On Error GoTo Err_Update
Dim strQueryName As String
DoCmd.SetWarnings (WarningsOff)
strQueryName = "uqUpdateMyTable"
MsgBox "MyTable is updated"
DoCmd.OpenQuery strQueryName, acNormal, acEdit
Exit_UpdateTable:
DoCmd.SetWarnings (WarningsOn)
Exit Sub
Err_Update:
MsgBox Err.Description
Resume Exit_UpdateTable
End Sub
Call the procedure from button's OnClick event. And you can change the procedure so it takes table name as parameter - then you can use the same procedure to run different update queries.