View Single Post
 
Old 04-05-2013, 09:51 AM
Elan05 Elan05 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Mar 2013
Posts: 13
Elan05 is on a distinguished road
Post Macro to Skip Calcuation if Field is Blank?!

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

Last edited by macropod; 04-05-2013 at 02:13 PM. Reason: Added code tags & formatting
Reply With Quote