none
Macro RRS feed

  • Question

  • I have a fill-form in Word 2010.  I used the Legacy text form field that allows you to apply a macro on Enter or Exit.  I would like to create a macro described below:

    When a user clicks in the field (bookmarked Text8), it checks to see if there is a date entered in the date field (bookmarked Text1).  I would apply the macro on enter in the field Text8. If there is a date entered in Text1, the user will be able to key info in Text8, etc.  If there is no date in Text1, a message box pops up that says “you must enter a date in the date field”  It then takes the user to Text1.

    Can this be done in a macro?

    Any help would be appreciated.

    Monday, January 30, 2017 3:15 PM

Answers

All replies

  • If you specify that the user can only enter dates in the Text1 form field, Text1 will be empty if the user hasn't entered a date.

    You can assign the following macro to On Enter of the Text8 form field:

    Sub Text8Entry()
        If ActiveDocument.FormFields("Text1").Result = "" Then
            MsgBox "You must enter a date in the date field!", vbExclamation
            ActiveDocument.FormFields("Text1").Range.Select
        End If
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, January 30, 2017 7:51 PM
  • This worked great!  I do have one field that is not working though.  The legacy field is a dropdown form field and not a text form field.  I would like to apply a macro like above on exit if the user tabs to another control.  I want a message box to prompt the user that they must first select from the dropdown.  The legacy field is bookmarked "Dropdown".  If I can get this working, it would be awesome.  Thank you in advance.

    Tuesday, February 14, 2017 3:43 PM
  • I'm using Word 2016, and I cannot leave a legacy dropdown form field empty...

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, February 14, 2017 5:07 PM
  • Actually that is very true.  And because of that, one of my selections is Select One.  I moved that all the way to the top so when I lock the form it looks like a label that says Select One.  Is there a way to have it verify the field for Select One and if it has Select One a message box pops up and prompts the user to make a selection from the dropdown on enter of that field?  Previously I was using check boxes but you can select more than one check box which is a problem for the user.  The user wants the person who's filling the form out only be able to select one checkbox, In the dropdown, you can only select one.  I don't have any other ideas for this field. 
    Tuesday, February 14, 2017 6:41 PM
  • You can display a message box on entering or on exiting the dropdown:

    Sub DropdownMessage()
        If ActiveDocument.FormFields("Dropdown").Result = "Select One" Then
            MsgBox "Please select an item from the dropdown list!", vbExclamation
        End If
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, February 14, 2017 8:10 PM
  • That worked perfectly. THANK YOU!!!!!
    • Marked as answer by Scacci Wednesday, February 15, 2017 3:47 PM
    Wednesday, February 15, 2017 3:47 PM
  • It appears that I am in need of a change in code.  Currently using a Legacy Drop Down form field and have recently switched over to a Content Control that is coming from SharePoint. Below is my current code and have no clue how to rewrite for the Content Control.  Also the Content Control is a Drop Down.  I have code set up on a Submit button.  When the user clicks on the Submit button, it verifies the field is not blank.  If blank, a Message Box requiring a selection goes off. Then the cursor goes to the field.  I believe you have helped me with the code for the Legacy form field.

    Any help would be appreciated.  Thank you in advance!!!!

    With ActiveDocument.FormFields("Dropdown")
            If .Result = "Select Result from Dropdown" Then
                MsgBox "Please select a result from the dropdown list!", vbExclamation
                Selection.GoTo what:=wdGoToBookmark, Name:="Dropdown"
                Exit Sub
            End If
        End With

    Tuesday, May 30, 2017 5:26 PM