textbox codes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have three TextBoxes
txtPrice,txtQty and txtTotal

i want codes for these textboxes,when a user put the price in txtPrice and
Quantity in txtQty,the txtTotal wil automatically show the the value i.e.
price*Qty=Total
is there anyone who can help me

thanks
 
Try this

Change the names to your TextBox names

With UserForm1
.TextBox3.Text = CDbl(.TextBox1.Text) * _
CDbl(.TextBox2.Text)
End With
 
Private Sub txtPrice_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
txtTotal.Text = txtPrice.Text * txtQty.Text
On Error GoTo 0
End Sub

Private Sub txtQty_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next
txtTotal.Text = txtPrice.Text * txtQty.Text
On Error GoTo 0
End Sub


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Many thanks for your reply,
kindly let me know where to put tese codes, there are many events in
textBox, like change,dblClick etc etc ????
 
and just adding to the bob's suggestion, if you want the total to change on
every number entry without leaving the textbox.

Private Sub txtPrice_Change()
On Error Resume Next
txtTotal.Text = txtPrice.Text * txtQty.Text
On Error GoTo 0

End Sub

Private Sub txtQty_Change()
On Error Resume Next
txtTotal.Text = txtPrice.Text * txtQty.Text
On Error GoTo 0

End Sub
 
See Bob's reply (Exit event)

You see that I use CDbl but in this case it is not needed but if you want to use
textbox1 + testbox2 you must use it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top