userform with calculations

I

ivory_kitten

my userform has 4 rates in text boxes called TFC, SFC, TRC and SRC. I also
have four text boxes called insuranceCost1, insuranceCost2, insuranceCost3
and insuranceCost4. When the user inputs a value in the text box called
insuranceValue, i want the values to display in the insuranceCost boxes. My
calculations are:

insuranceCost1 * TFC
insuranceCost2 * SFC
insuranceCost3 * TRC
insuranceCost4 * SRC

How can I do this with VBA?
 
A

aidan.heritage

Use the exit event of the textbox InsuranceValue with the following
code:

InsuranceCost1.text=val(TFC)* val(InsuranceValue)
InsuranceCost2.text=val(SFC)* val(InsuranceValue)
InsuranceCost3.text=val(TRC)* val(InsuranceValue)
InsuranceCost4.text=val(SRC)* val(InsuranceValue)
 
I

ivory_kitten

I get error message:

Run-time error '13':

Type mismatch

This is the code I have

Private Sub InsuranceValue_Exit(ByVal Cancel As MSForms.ReturnBoolean)
InsuranceCost1.Text = Val(TFC) * Val(InsuranceValue)
InsuranceCost2.Text = Val(SFC) * Val(InsuranceValue)
InsuranceCost3.Text = Val(TRC) * Val(InsuranceValue)
InsuranceCost4.Text = Val(SRC) * Val(InsuranceValue)
End Sub
 
J

Jean-Guy Marcil

ivory_kitten was telling us:
ivory_kitten nous racontait que :
I get error message:

Run-time error '13':

Type mismatch

This is the code I have

Private Sub InsuranceValue_Exit(ByVal Cancel As MSForms.ReturnBoolean)
InsuranceCost1.Text = Val(TFC) * Val(InsuranceValue)
InsuranceCost2.Text = Val(SFC) * Val(InsuranceValue)
InsuranceCost3.Text = Val(TRC) * Val(InsuranceValue)
InsuranceCost4.Text = Val(SRC) * Val(InsuranceValue)
End Sub
What are the values of TFC, SFC, TRC, SRC and InsuranceValue?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
I

ivory_kitten

TFC is a percentage value and Insurance Value is $

i.e. TFC = 2.20% and insurance value = $10,000.00
the result needs to show as $220.00
 
A

aidan.heritage

Restrict the inputs to numeric and decimal point ONLY - otherwise you
will have to remove non numeric characters before doing the
calculation.
 
J

Jean-Guy Marcil

ivory_kitten was telling us:
ivory_kitten nous racontait que :
TFC is a percentage value and Insurance Value is $

i.e. TFC = 2.20% and insurance value = $10,000.00
the result needs to show as $220.00

If you are using Val(string), do not use "%" and "$" in the strings

Also, you need to use:

(Val(TFC)/100)*Val(Insurance value)

and not just


Val(TFC) *Val(Insurance value)


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
I

ivory_kitten

how do you remove them? the values in those fields also show on the
quotation template and need to have those formats.

and will it calculate a percentage?
 
J

Jean-Guy Marcil

ivory_kitten was telling us:
ivory_kitten nous racontait que :
how do you remove them? the values in those fields also show on the
quotation template and need to have those formats.

Easier to leave them out in the userform, and then use Format to format the
string when inserting the userform info in the document.

See "Format" in the VBA on-line help for examples.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Doug Robbins - Word MVP

You will make it a lot easier for your users if all they have to do is enter
the numeric part and use a formatting switch to add the currency or percent
format where you want that to appear.

You can use the Left(), Right(), or Mid() functions the get part of the
string.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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

Top