calculate vba userform type mismatch when decimal is entered

P

Pam

I have a vba userform that I want to calculate fields.
I have a quantity, unit price, and want the calculation to be in the
extended price field.
I'm using the following code, and it works great, as long as you use a
number not starting with a decimal. ie.. I can input 1 x 1.50 and it works,
or I can enter 1 x 0.50 and it works, but if I enter 1 x .5 it errors out as
a type mismatch.
What am I doing wrong?
Thank you

Private Sub Txtitemunit1_Change()
If Me.TxtItemQty1.Value <> "" Then
Me.TxtItemExt1.Value = Me.TxtItemUnit1.Value * Me.TxtItemQty1.Value
End If
End Sub
 
N

Nigel

The problem lies with the empty box which is text, text * value = Error !!

so try the following to force values ....

Me.TxtItemExt1.Value = Val(Me.TxtItemUnit1.Value) *
Val(Me.TxtItemQty1.Value)
 

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

Similar Threads


Top