PC Review


Reply
Thread Tools Rate Thread

calculate vba userform type mismatch when decimal is entered

 
 
Pam
Guest
Posts: n/a
 
      28th Dec 2008
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
 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      28th Dec 2008
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)


--

Regards,
Nigel
(E-Mail Removed)



"Pam" <(E-Mail Removed)> wrote in message
news:F31694AF-4249-47BE-9227-(E-Mail Removed)...
>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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
type mismatch when opening a userform SMS Microsoft Excel Programming 2 2nd Oct 2009 11:24 PM
How to type format time in decimal format & calculate Cheyenne Microsoft Excel Misc 1 12th Feb 2009 11:54 PM
How to calculate time in 1/100 decimal while it is entered 1/60 =?Utf-8?B?enliZXJkb2M=?= Microsoft Excel Programming 4 16th Mar 2006 04:23 PM
Passing Userform Listbox to sub causes type-mismatch error =?Utf-8?B?S2xlZXY=?= Microsoft Excel Programming 2 19th Oct 2005 08:46 PM
Type mismatch error (different than previous type mismatch?) Roberta Microsoft Access VBA Modules 3 9th Jan 2004 06:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 PM.