Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA Calculate TextBox Values for Data Validation ~Math 2

Status
Not open for further replies.

DTechDonna

Instructor
Jan 3, 2011
6
US
I have prepared a multipage UserForm in Word 2007 using the tools in VBA. What I would like to do is this. On one tab are numbers representing costs. The costs cannot exceed $5,000. There are two boxes that need to be looked at with the user's entries added together to determine if they exceed $5,000. If the entries are over $5,000, I want the user to have a 'stop message' when they click the Next Button. I know how to do the Stop Message. I do not know how to program the Add values of the text boxes and check to see if they are greater than $5,000. I could really use some help please. The sum of the two boxes does not need to appear anywhere. By the way, the results of the UserForm eventually get dumped into a Word document via variables and bookmarks. Thank you for taking a stab at this. I'm stuck. -Donna
 


What code do you have so far? Exactly where are you stuck?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'm stuck at the syntax for adding and comparing mathematically two text boxes. It provides strange results so it's can't be right and I seem to find clues on the Internet anywhere. I appreciate your input. Here's what I have so far:

If (Me.Pay_the_sum_of_TextBox.Value + Me.County_Reimburse_OOP_TextBox.Value) > 5000# And Me.Pay_at_NTE_TextBox.Visible = False And Me.Pay_hourly_NTE_TextBox.Visible = False Then
MsgBox "This form is to be used for contracts not to exceed $5,000"
Me.MultiPage1.Value = 3
Else
Me.MultiPage1.Value = 4
 


your PLUSE is probably CONCATENATING the two TEXT values rather than doing a mathematical evaluation...
Code:
If ([b]CCur([/b]Me.Pay_the_sum_of_TextBox.Value) + [b]CCur([/b]Me.County_Reimburse_OOP_TextBox.Value)) .......


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about this ?
If (Val(Me.Pay_the_sum_of_TextBox.Value) + Val(Me.County_Reimburse_OOP_TextBox.Value)) > 5000 And ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV ~ I tried your, If(Val(Me.Pay...) and it works beautifully. Just right. Thank you very much. Nice. Just what I needed to "get out of jail". Don't know who you are but I owe you now. The universe sends best mojo your way. Thank you. -Donna in Minneapolis, MN
 
Now that I'm cooking with Comparisons of two text boxes, I need to do another. Here's the situation. I am using bookmarks and Hidden Text within the Word Document in this instance to update the Word doc from the same userform created in VBA. I am comparing the same two text boxes and based on the results of the math signature blocks are inserted at the bottom of the contract. The variable is if the dollar calculated is over $5,000 then insert one signature; if under, another. Here's the code. It doesn't work. I can't get it to insert the Over $5,000 Signature at all with this code, even when one of the boxes is entered over $5,000. Perhaps the math variable cannot work with bookmarks? Perhaps I don't have the code entered correctly? Ideas? thank you! -Donna

'Signature Line
With ActiveDocument.Bookmarks
If (Val(Me.Pay_the_sum_of_TextBox.Value) + Val(Me.County_Reimburse_OOP_TextBox.Value)) <= 5000 Then
.Item("Signature_5000").Range.Font.Hidden = False
Else
.Item("Signature_5000_25000").Range.Font.Hidden = False
End If
End With


 
I see what you mean Skip with CCur and the value of counting Currency. Nice. Thank you. As I'm a beginner with VBA this is good stuff. -Donna
 


CCur and the value of counting Currency
CONVERSION of string to currency.

Check VB Help on CCur and it will also show you many other type conversions with some explanation.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks all. And I figured out my Bookmark issue. I just didn't have the code all arranged. Case closed. Good forum. My first experience - and a good one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top