View Single Post
 
Old 03-07-2017, 02:26 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The following code, when placed in the ‘ThisDocument’ module, prevents the document being closed if it contains any formfields that have not been filled in.
Code:
Private Sub Document_Close()
Dim FFld As FormField, Doc As Document
Set Doc = ActiveDocument
For Each FFld In Doc.FormFields
  If Trim(FFld.Result) = "" Then
    MsgBox "Please complete all the items"
    If Doc.Saved = True Then Doc.Reload
    Exit Sub
  End If
Next
End Sub
To test for whether designated formfields (in this case, “Text1” & “Text7”) have been completed, you might use code like:
Code:
Private Sub Document_Close()
Dim FFld As FormField, Doc As Document
Set Doc = ActiveDocument
For Each FFld In Doc.FormFields
  Select Case FFld.Name
    Case "Text1", "Text7"
      If Trim(FFld.Result) = "" Then
        MsgBox "Please complete the mandatory items"
        If Doc.Saved = True Then Doc.Reload
        Exit Sub
      End If
  End Select
Next
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote