I need a Word macro to check, upon file exit or file close, that certain specified text fields (legacy form fields, not content controls) are empty.
I have code that is a pretty intrusive warning box. It is contingent on the user selecting that field, then the macro pops up a warning box either upon entry or exit, as specified in the form field properties menu. I have several fields,"Text1", "text2", then text7 thru 11.
Trouble is, the user MUST select a field. On top of that, the warning box sends them into a death loop before they can close the file. I also have to make a new module for each of fields with the code below.
Perhaps the best solution here is a macro that runs on close and/or exit of the file, which says "Hey you forgot to fill out these fields, they are 'mandatory' so go back and do that please, thanks!".
Sub MustFillIn3()
If ActiveDocument.FormFields("Text2").Result = "" Then
Do
sInFld = InputBox("Request date required, please fill in below.")
Loop While sInFld = ""
ActiveDocument.FormFields("Text2").Result = sInFld
End If
End Sub
Yes, just write the check code in the event handler procedure Document_Close in ThisDocument object, like this
This check sub is triggered when the current document is closed and is not related to whether ff has focus or not (ie. the user Doesn't MUST select a field ).
You have to run this sub to Register Event_Handler to Word Application.
As for the details, you should adjust them yourself. Try to understand the code I have given you to simulate it. Come back to StackOverflow and ask a new question when you encounter difficulties and problems in the implementation.
I've used the text field to test:
Is this yours?
Before closing the document check if it has been modified