Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Box in a user form 1

Status
Not open for further replies.

robcarr

Programmer
May 15, 2002
633
GB
Dear All,

I have a TBProfitLoss(textbox in a form in EXCEL) that I need to automatically sum 3 other text boxes in the form (TBSoldFor+TBSpend-TbBuyPrice) when TBSoldFor gets a value entered in to it, is it possible to show the profit or loss instantly when TBSoldFor gets a value without saving the record.

Any help is greatly appreciated.


Thanks Rob.[yoda]
 
Try this (all in the User Form module):
Code:
Sub CalcProfit()
Dim nSoldFor As Double
Dim nSpend As Double
Dim nBuyPrice As Double
  nSoldFor = 0 & TBSoldFor.Value
  nSpend = 0 & TBSpend.Value
  nBuyPrice = 0 & TBBuyPrice.Value
  TBProfitLoss = nSoldFor + nSpend - nBuyPrice
End Sub

Private Sub TBBuyPrice_Change()
  CalcProfit
End Sub

Private Sub TBSoldFor_Change()
  CalcProfit
End Sub

Private Sub TBSpend_Change()
  CalcProfit
End Sub
Also, I would set the "Locked" property for TBProfitLoss to True.
HTH

 
thanks HTH that worked a treat Thanks Rob.[yoda]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top