word forms

  • Thread starter Thread starter Guest
  • Start date Start date
See http://www.word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm for
the sort of macro solution you need.

For a dropdown, the If statement in the macro is a bit different from
the one shown there for a text form field. I assume that the first
item on the dropdown list is either a blank or a prompt rather than an
actual choice. This code looks at the .Dropdown.Value (that is, the
number of the selected item in the list) instead of the .Result:

Sub ExitDropdown1()
With ActiveDocument.FormFields("Dropdown1")
If .DropDown.Value = 1 Then
Application.OnTime When:=Now + TimeValue("00:00:01"), _
Name:="GoBacktoDropdown1"
MsgBox "A selection is required."
End If
End With
End Sub

Sub GoBacktoDropdown1()
ActiveDocument.Bookmarks("Dropdown1").Range.Fields(1).Select
End Sub

The problem with this sort of validation is that it relies on the user
tabbing or clicking into and out of the field. If they use the mouse
to select other fields and never enter the dropdown, the macro won't
run at all. To prevent that, you need other macros to intercept the
Save and Print commands and check that the dropdown has a valid
selection at that time
(http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
See http://www.word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm for
the sort of macro solution you need.

For a dropdown, the If statement in the macro is a bit different from
the one shown there for a text form field. I assume that the first
item on the dropdown list is either a blank or a prompt rather than an
actual choice. This code looks at the .Dropdown.Value (that is, the
number of the selected item in the list) instead of the .Result:

Sub ExitDropdown1()
With ActiveDocument.FormFields("Dropdown1")
If .DropDown.Value = 1 Then
Application.OnTime When:=Now + TimeValue("00:00:01"), _
Name:="GoBacktoDropdown1"
MsgBox "A selection is required."
End If
End With
End Sub

Sub GoBacktoDropdown1()
ActiveDocument.Bookmarks("Dropdown1").Range.Fields(1).Select
End Sub

The problem with this sort of validation is that it relies on the user
tabbing or clicking into and out of the field. If they use the mouse
to select other fields and never enter the dropdown, the macro won't
run at all. To prevent that, you need other macros to intercept the
Save and Print commands and check that the dropdown has a valid
selection at that time
(http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Thanks for your help.

Jay Freedman said:
See http://www.word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm for
the sort of macro solution you need.

For a dropdown, the If statement in the macro is a bit different from
the one shown there for a text form field. I assume that the first
item on the dropdown list is either a blank or a prompt rather than an
actual choice. This code looks at the .Dropdown.Value (that is, the
number of the selected item in the list) instead of the .Result:

Sub ExitDropdown1()
With ActiveDocument.FormFields("Dropdown1")
If .DropDown.Value = 1 Then
Application.OnTime When:=Now + TimeValue("00:00:01"), _
Name:="GoBacktoDropdown1"
MsgBox "A selection is required."
End If
End With
End Sub

Sub GoBacktoDropdown1()
ActiveDocument.Bookmarks("Dropdown1").Range.Fields(1).Select
End Sub

The problem with this sort of validation is that it relies on the user
tabbing or clicking into and out of the field. If they use the mouse
to select other fields and never enter the dropdown, the macro won't
run at all. To prevent that, you need other macros to intercept the
Save and Print commands and check that the dropdown has a valid
selection at that time
(http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Thanks for your help.

Jay Freedman said:
See http://www.word.mvps.org/FAQs/TblsFldsFms/ValidateFFields.htm for
the sort of macro solution you need.

For a dropdown, the If statement in the macro is a bit different from
the one shown there for a text form field. I assume that the first
item on the dropdown list is either a blank or a prompt rather than an
actual choice. This code looks at the .Dropdown.Value (that is, the
number of the selected item in the list) instead of the .Result:

Sub ExitDropdown1()
With ActiveDocument.FormFields("Dropdown1")
If .DropDown.Value = 1 Then
Application.OnTime When:=Now + TimeValue("00:00:01"), _
Name:="GoBacktoDropdown1"
MsgBox "A selection is required."
End If
End With
End Sub

Sub GoBacktoDropdown1()
ActiveDocument.Bookmarks("Dropdown1").Range.Fields(1).Select
End Sub

The problem with this sort of validation is that it relies on the user
tabbing or clicking into and out of the field. If they use the mouse
to select other fields and never enter the dropdown, the macro won't
run at all. To prevent that, you need other macros to intercept the
Save and Print commands and check that the dropdown has a valid
selection at that time
(http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Back
Top