Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Form Fields - next destination dependant on drop-down selection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MattB - 20 Nov 2006 16:53 GMT
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
Signature

MattB

Jay Freedman - 20 Nov 2006 17:35 GMT
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.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi,
>
[quoted text clipped - 10 lines]
> Word knowledge now.
> TIA
MattB - 21 Nov 2006 09:54 GMT
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.
Signature

MattB

> Hi Matt,
>
[quoted text clipped - 22 lines]
> > Word knowledge now.
> > TIA
Jay Freedman - 21 Nov 2006 15:50 GMT
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.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> Hi Jay,
>
[quoted text clipped - 44 lines]
>>> Word knowledge now.
>>> TIA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.