• Can you have a field become required based on a previous field selection?

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Can you have a field become required based on a previous field selection?

    Author
    Topic
    #502603

    Hi

    I have a ‘new starter’ type form created in Word 2013 using form fields. Currently I have a field called ‘Employee Type’ which is a drop down list. What I would like to happen is that if somebody chooses ‘Contractor’ that the next field, called ‘End Date’, becomes a required field. I am almost certain this cannot be done through the native commands, but am wondering if this is something that can be programmed via VBA. Does anybody know if it can be done and how?

    Thanks, Laurie

    Viewing 3 reply threads
    Author
    Replies
    • #1531876

      Yes, you could use a macro to make a field ‘required’. There are two ways this could be implemented:
      1. Use an on-exit macro attached to the ‘Employee Type’ field, coded such that, if ‘Contractor’ is chosen, the ‘End Date’ field is selected and use an on-exit macro attached to that field also, to test whether the ‘Employee Type’ field displays ‘Contractor’ and, if so, re-select itself if a valid date isn’t input; or
      2. Use a Document_Close macro to test whether the ‘Employee Type’ field displays ‘Contractor’ and, if so, reload the document if the ‘End Date’ field lacks a valid date.
      Either approach, of course, requires the user to allow macros in the document to run.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1531959

        Hi

        Thanks for this, that’s really useful. I will investigate further and see how I get on.

        Thanks again.

    • #1531981

      Hi LaurieW
      The attached word document has an example form that demonstrates activating a text box control based on the contents of a combobox.

      This is not a complete solution, merely a demonstration. You would need error checking and validation. For example check for valid dates
      You might find a need to capture other events than those I show here.
      I hope it helps.

      Geof

    • #1532001

      Geoff, your attachment is based on the assumption the OP has a userform. However, the OP says in post #1 that he is using formfields, which are entirely different.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1532003

        Geoff, your attachment is based on the assumption the OP has a userform. However, the OP says in post #1 that he is using formfields, which are entirely different.

        Hi Paul
        Oops, a critical misread of the original post.
        I will delete the post.
        Geof
        😡

    • #1532007

      As I said in post #2 regarding formfields, you might one might use a Document_Close macro. Such a macro might be coded along the lines of:

      Code:
      Private Sub Document_Close()
      With ThisDocument
        If .FormFields("Employee_Type").Result = "Contractor" Then
          If .FormFields("End_Date").Result = "" Then
            MsgBox "Please Input the Contractor's End Date", vbCritical
            If .Saved = True Then .Reload
            Exit Sub
          End If
        End If
      End With
      End Sub

      This is the simpler of the two implementations, but might not meet the OP’s needs. Since the ‘End_Date’ formfield can be formatted to accept only date inputs, that’s one aspect of validation the macro wouldn’t need do, though one still might want to test whether an out-of-bounds date has been input.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1532048

        Brilliant looks perfect thanks. I am not an expert in VBA, I am requesting this on behalf of someone else so let me see how they get on with that.

        Thanks again.

    Viewing 3 reply threads
    Reply To: Can you have a field become required based on a previous field selection?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: