Share via

Making Fields in a Word Form Mandatory to complete

Anonymous
2019-07-10T19:15:43+00:00

I am trying to make certain form fields in a Word document as mandatory to complete, and have used a Macro that I have found on other sites that should work.  However, when I try to run it, I get the message "Run Time error 5941 The requested member of the collection does not exist".

I am new to macros, but really need to get this to work!  Can anyone help with this?  I am able to upload the form for you to look at, but can't see a way of doing this currently.  Any advice is much appreciated!

Emma.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Jay Freedman 207.6K Reputation points Volunteer Moderator
    2019-07-11T20:20:06+00:00

    That macro is intended for use with legacy form fields and won't do anything with content controls.

      

    Also, the "filling in forms" type of editing restriction is for legacy form fields, not for content controls.

    At this point, the simplest way to get your form working is to replace each content control with the corresponding form field. After inserting a form field, click the Properties button to get its properties dialog, which is different from the one for content controls. Put the field's name in the "Bookmark" box -- that name is what the macro will use to identify the field. In the Exit dropdown, select the name of the macro (MustFillIn).

    If you prefer to use the content controls, then you need a different macro. This goes in the ThisDocument module of your document or template:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)

        If ContentControl.Title = "fullname" And ContentControl.ShowingPlaceholderText = True Then

            MsgBox "This field must be filled in.", vbExclamation, "Required Field"

            Cancel = True

        End If

    End Sub

    In either of these cases, the macro won't run if the user's cursor never enters the field or content control. If you want the check for an empty field to happen when they save or close the document, regardless of whether the field has been visited, then you need a different macro, one that's unfortunately rather more complicated.

    9 people found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-07-11T18:57:45+00:00

    I'm using the Developer tools to insert check boxes and text boxes, and on the Restrict Editing tool bar I have selected filling in forms as the editing restriction.  I have also saved the form as macro enabled.

    The script I am using is as follows:

    Sub MustFillIn()

        If ActiveDocument.FormFields("fullname").Result = "" Then

            Do

                sInFld = InputBox("This field must be filled in, fill in below.")

            Loop While sInFld = ""

            ActiveDocument.FormFields("fullname").Result = sInFld

        End If

    End Sub

    I have named the fields using the content control properties box, as shown below:

    Is there some other way of naming the field that I should use?  Again, I am happy to send you the Word document for you to look at, there are no details on it.

    Thanks,

    Emma.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2019-07-17T18:15:22+00:00

    Hi Jay,

    Sorry for the late reply.  The above worked perfectly!  Many thanks.

    0 comments No comments
  3. Anonymous
    2019-07-11T21:37:50+00:00

    Many thanks, that completely makes sense. Will try and correct my form fields tomorrow, and let you know how I get on!

    0 comments No comments
  4. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2019-07-10T22:53:22+00:00

    What type of controls are you using on the form and what is the code of the macro that you tried to use?

    The 5941 error is probably caused by a reference to a bookmark that does not exist in the document.

    0 comments No comments