Need help with Word form macro

K

Kim17740

Here's the setup... I have a form that has a drop down list field. When the
user selects "other" from the list I want them to be automatically directed
to the next blank text field where they will have to enter what "other" is.

I've never been good at setting up macros so any help will be greatly
appreciated.

Thanks.
 
J

Jean-Guy Marcil

Kim17740 was telling us:
Kim17740 nous racontait que :
Here's the setup... I have a form that has a drop down list field.
When the user selects "other" from the list I want them to be
automatically directed to the next blank text field where they will
have to enter what "other" is.

I've never been good at setting up macros so any help will be greatly
appreciated.

Perhaps something along those lines:

'_______________________________________
With ActiveDocument.FormFields
If Selection.Range.FormFields(1).Result = "Other" Then
.Item("otherTxt").Enabled = True
.Item("otherTxt").Range.Fields(1).Result.Select
Else
.Item("otherTxt").Enabled = False
.Item("skipTxt").Range.Fields(1).Result.Select
End If
End With
'_______________________________________

Just change "otherTxt" and "skipTxt" for your target text fields.

Note that I disabled the "Other" text fields whenever the dropdown value is
not "Other". This way the user cannot inadvertently enter a value that is
not necessary or that could be misleading (If "Other" is *not* selected, but
a text is entered in the "Other" text field, where is the error? Is the
error in the text field or the drop down? This way, you do not have to
worry. You could even add code to set the "Other" text field to an empty
string whenever something other than "Other" is selected in the dropdown:

'_______________________________________
With ActiveDocument.FormFields
If Selection.Range.FormFields(1).Result = "Other" Then
.Item("otherTxt").Enabled = True
.Item("otherTxt").Range.Fields(1).Result.Select
Else
.Item("otherTxt").Result = ""
.Item("otherTxt").Enabled = False
.Item("skipTxt").Range.Fields(1).Result.Select
End If
End With
'_______________________________________

Better be proactive regarding user errors because Murphy's law absolutely
applies in those situations...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top