Form Fields - next destination dependant on drop-down selection

M

MattB

Hi,

I'm trying to edit a form where there are a number of text and drop-down
fields. What I'd like to do is have the user of the form select a drop-down
answer, and for the form to take them to the next relevant point (bookmark?)
based on that answer.

For example, if the answer to a question means the rest of the form can be
skipped, how do I automate it so that the form jumps to the 'Thankyou'
message at the end?

I'm certain this can be done, but I'm pushing the boundaries of my Word
knowledge now.
TIA
 
J

Jay Freedman

Hi Matt,

You can expand the macro in Method 2 of
http://www.word.mvps.org/FAQs/TblsFldsFms/SetTabOrder.htm. That macro simply
selects the "next field to go to" by looking at the name of the current
field. What you need to do is to look at the value of the current field (if
it's a dropdown) and choose a different "next field" depending on what that
value is.

If that description doesn't get you far enough, post back and include
whatever code you have so far, plus some sample field names and values.

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

MattB

Hi Jay,

Thanks for the details. Unfortunately I haven't got very far with this apart
from creating the fields and values - that's where what little ability I had
has run out...

The fields themselves are named Q3a, Q3b, Q4a etc and the available answers
are either Yes/No or All Locations/Some Locations/None. It would therefore
help users of the form that if they answer 'None' to Q3a for example, 3b, 3c
are skipped (as they're no longer applicable) and Q4a is the next to be
answered.

Thanks for your help.
 
J

Jay Freedman

Hi Matt,

This is the macro from the web page, modified to work with your dropdowns.
Assign this macro as the exit macro for each dropdown that needs this kind
of redirection, and create a case for each dropdown following the models I
show:

Sub TabOrder()

Dim StrCurFFld As String, StrFFldToGoTo As String

'First get the name of the current formfield
If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
StrCurFFld = Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And _
Selection.Bookmarks.Count > 0 Then
'Textbox
StrCurFFld = _
Selection.Bookmarks(Selection.Bookmarks.Count).Name
End If

'Then find out which formfield to go to next ...
Select Case StrCurFFld
Case "Q3a"
' the dropdown's "value" is the number
' of the selected item, starting from 1
If Selection.FormFields(1).DropDown.Value = 3 Then
' selected "None", the 3rd item
' so skip to next dropdown
StrFFldToGoTo = "Q4a"
Else
' selected something else, so
' continue to next text field in this group
StrFFldToGoTo = "Q3b"
End If
Case "Q4a"
If Selection.FormFields(1).DropDown.Value = 2 Then
' selected "No", the 2nd item
StrFFldToGoTo = "Q5a"
Else
StrFFldToGoTo = "Q4b"
End If
Case Else
' any other field that doesn't need redirection
StrFFldToGoTo = ""
End Select

' ... and go to it
' or just go to the next field if StrFFldToGoTo = ""
If StrFFldToGoTo <> "" Then
' if the destination is a text formfield,
' use the more complicated selection method
If ActiveDocument.FormFields(StrFFldToGoTo).Type = _
wdFieldFormTextInput Then
ActiveDocument.Bookmarks(StrFFldToGoTo).Range _
.Fields(1).Result.Select
Else
ActiveDocument.FormFields(StrFFldToGoTo).Select
End If
End If

End Sub


In testing this macro, I found that the .Select statement at the end of the
original version will select only a text formfield. If you want the
selection to jump to the next dropdown, you need the other .Select statement
shown here.

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

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