Hello,
I have the following macro in my document to calculate a payment amount, based on the times per year the contract is invoiced. My macro is repeated for Year3 - Year5... I wanted to know if there is something that I can add to this so that if any years beyond the Year1 are not filled in (form field left blank) the macro won't try to calculate. Right now, if some of the form fields aren't filled in, I get an error message when I exit the fields that are empty.
Code:
Sub CalcPayable()
'
' CalcPayable Macro
If ActiveDocument.FormFields("Cycle").Result = "Annually" Then
ActiveDocument.FormFields("Payable1").Result = ActiveDocument.FormFields("Year1").Result
ElseIf ActiveDocument.FormFields("Cycle").Result = "Semiannually" Then
ActiveDocument.FormFields("Payable1").Result = ActiveDocument.FormFields("Year1").Result / 2
ElseIf ActiveDocument.FormFields("Cycle").Result = "Quarterly" Then
ActiveDocument.FormFields("Payable1").Result = ActiveDocument.FormFields("Year1").Result / 4
ElseIf ActiveDocument.FormFields("Cycle").Result = "Bimonthly" Then
ActiveDocument.FormFields("Payable1").Result = ActiveDocument.FormFields("Year1").Result / 6
ElseIf ActiveDocument.FormFields("Cycle").Result = "Monthly" Then
ActiveDocument.FormFields("Payable1").Result = ActiveDocument.FormFields("Year1").Result / 12
ElseIf ActiveDocument.FormFields("Cycle").Result = "Triannually" Then
ActiveDocument.FormFields("Payable1").Result = ActiveDocument.FormFields("Year1").Result / 3
End If
If ActiveDocument.FormFields("Cycle").Result = "Annually" Then
ActiveDocument.FormFields("Payable2").Result = ActiveDocument.FormFields("Year2").Result
ElseIf ActiveDocument.FormFields("Cycle").Result = "Semiannually" Then
ActiveDocument.FormFields("Payable2").Result = ActiveDocument.FormFields("Year2").Result / 2
ElseIf ActiveDocument.FormFields("Cycle").Result = "Quarterly" Then
ActiveDocument.FormFields("Payable2").Result = ActiveDocument.FormFields("Year2").Result / 4
ElseIf ActiveDocument.FormFields("Cycle").Result = "Bimonthly" Then
ActiveDocument.FormFields("Payable2").Result = ActiveDocument.FormFields("Year2").Result / 6
ElseIf ActiveDocument.FormFields("Cycle").Result = "Monthly" Then
ActiveDocument.FormFields("Payable2").Result = ActiveDocument.FormFields("Year2").Result / 12
ElseIf ActiveDocument.FormFields("Cycle").Result = "Triannually" Then
ActiveDocument.FormFields("Payable2").Result = ActiveDocument.FormFields("Year2").Result / 3
End If
End Sub