PDA

View Full Version : Excel VBA UserForm TxtBox Calulations



Sherrise
11-02-2016, 12:50 PM
Hello, this is my first time posting. I am very new at VBA Coding. Please help.

I have a Mulitab Form Called UserForm1. One of my tabs is called Cost Recovery. On this form I have the following text boxs called Original Amount Owing, this is an input box, All the AmountsPaid are input boxes AmountPaid1, AmountPaid2, AmountPaid3, Balance Owing.

I want a message to popup if there is a error on any of the input txtboxes to say "in correct. Try again".

And for the balance to calculate each time in the balance txbox.


Please, Please help. I have tried everything and cannot get this to work.

Kenneth Hobs
11-02-2016, 03:29 PM
Welcome to the forum!

I am not sure what would cause an error.

Change the textbox control names to suit. Note how I cancel the exit if the string is not numeric and not empty. Note how I used Val() to do the sum.

Paul_Hossler
11-02-2016, 05:15 PM
Change the textbox control names to suit. Note how I cancel the exit if the string is not numeric and not empty. Note how I used Val() to do the sum.


Forget something ?? :devil2:

(Cheap shot, but I couldn't resist since I'm having that kind of day too)

Kenneth Hobs
11-02-2016, 05:36 PM
It could be my mind but maybe you mean code?


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) If Not IsNumeric(TextBox1) And TextBox1 <> "" Then
Cancel = True
Exit Sub
End If

SumTextBoxes
End Sub


Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox2) And TextBox2 <> "" Then
Cancel = True
Exit Sub
End If

SumTextBoxes
End Sub


Private Sub SumTextBoxes()
TextBox3 = Val(TextBox1) + Val(TextBox2)
End Sub

Sherrise
11-03-2016, 09:39 AM
I will try this. This is such a great site to help people who are new and trying to learn. I am very much appreciative. Thank you