Consulting

Results 1 to 4 of 4

Thread: DocumentBeforeClose Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Nov 2021
    Posts
    1
    Location

    DocumentBeforeClose Help

    Hi all,

    I am trying to validate all form fields in a Word doc prior to close and message the user that these fields must be completed before the doc closes. Once they have clicked 'OK', I want the doc to stay open to allow them to update mandatory fields. This what I have so far (which doesn't work):

    Private Sub DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
     Dim intResponse As Integer
     Dim FFld As FormField
     Set Doc = ActiveDocument
     For Each FFld In Doc.FormFields
        If Trim(FFld.Result) = "" Then
        intResponse = MsgBox("Please enter a value in each field", vbOKOnly)
     'Cancel = True will prevent the document from closing once the sub is complete
     'Cancel = False will close the document after sub is complete.
     Cancel = True
     End If
     Next
    End Sub


    Thanks for your help!
    Last edited by Paul_Hossler; 11-19-2021 at 07:59 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •