formulas

T

tony

I am using word 2003 and am using text form fields in a table. I will
use my bookmark names here with a brief explanation of what I am
actually trying to accomplish, and hopefully it will make some sense
and someone could help. I can accomplish this in Excel no problem,
but Word is a different world.
Working inside the table, I am trying to get Text109 (Deposit amount
due to landlord) to calculate by taking Text112 (Deposit total) and
subtracting Text108 (total amount due to landlord) and if it is equal
to or less than zero, then show zero, but if not then show the
balance. And then I am trying to get Text110 (Rent amount due to
landlord) to calculate Text111 less Text108 (Rent total) only if
Text112 (Deposit total) is equal to or less than zero.
In other words, I would like to first apply the amount received by
landlord to first apply to the deposit and then apply to the rent and
show any overpayment as a zero balance in the deposit field and as a
credit in the rent amount due to landlord.
I am sorry if this explanation rambles.
Thank you,
Tony
 
G

Graham Mayor

This would work best with a macro run on exit from the last required field
Text112. If I have understood the requirement correctly then the following
should work. Uncheck the allow fill-in property for the two calculated
fields.

Sub CalcTotal()
Dim sDep As String
Dim sDue As String
Dim sRent As String
Dim sCalc1 As String
Dim sCalc2 As String

With ActiveDocument
sDep = .FormFields("Text112").Result
sDue = .FormFields("Text108").Result
sRent = .FormFields("Text111").Result

sCalc1 = sDep - sDue
If sCalc1 <= 0 Then sCalc1 = 0
.FormFields("Text109").Result = sCalc1

sCalc2 = sRent - sDue
If sDep <= 0 Then sCalc2 = 0
.FormFields("Text110").Result = sCalc2

End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

tony

This would work best with a macro run on exit from the last required field
Text112. If I have understood the requirement correctly then the following
should work. Uncheck the allow fill-in property for the two calculated
fields.

Sub CalcTotal()
Dim sDep As String
Dim sDue As String
Dim sRent As String
Dim sCalc1 As String
Dim sCalc2 As String

With ActiveDocument
    sDep = .FormFields("Text112").Result
    sDue = .FormFields("Text108").Result
    sRent = .FormFields("Text111").Result

sCalc1 = sDep - sDue
    If sCalc1 <= 0 Then sCalc1 = 0
    .FormFields("Text109").Result = sCalc1

     sCalc2 = sRent - sDue
    If sDep <= 0 Then sCalc2 = 0
    .FormFields("Text110").Result = sCalc2

End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>




- Show quoted text -

I have tried the macro but I am still having trouble. If there is
some way that I could post the table itself maybe you could see it in
context and then you could show me so that it could make sense to me.
Thank you,
Tony
 

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