Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    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
    [MS MVP - Word]

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

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

    Thanks again.

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    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
    [MS MVP - Word]

  5. #5
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Levin, Manawatu-Wanganui, New Zealand
    Posts
    324
    Thanks
    9
    Thanked 28 Times in 26 Posts
    Quote Originally Posted by macropod View Post
    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

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    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
    [MS MVP - Word]

  7. #7
    Star Lounger
    Join Date
    Jan 2003
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

Posting Permissions

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