Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Chris Chris is offline
external usenet poster
 
Posts: 237
Default Hide questions in a questionnaire - macro needed?

I am trying to understand if it is possible to create a questionnaire where
questions are hidden until a certain answer is given.

E.g. Answer 'No' to question 1, then question 1b opens up that asks a
further question.

I presume some sort of macro would be needed for this? Any help much
appreciated.
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Hide questions in a questionnaire - macro needed?

Chris,

If you mean to open up as in display on the screen and print then you
may be able to adapt the method shown here to your needs:

http://gregmaxey.mvps.org/Toggle_Data_Display.htm


chris wrote:
I am trying to understand if it is possible to create a questionnaire where
questions are hidden until a certain answer is given.

E.g. Answer 'No' to question 1, then question 1b opens up that asks a
further question.

I presume some sort of macro would be needed for this? Any help much
appreciated.


  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Chris Chris is offline
external usenet poster
 
Posts: 237
Default Hide questions in a questionnaire - macro needed?

Greg - thanks. That's almost it but I want the question to be hidden and only
expand when a certain answer is given (rather than a button to double click).
Do you think that's possible or will I have to use excel?

"Greg Maxey" wrote:

Chris,

If you mean to open up as in display on the screen and print then you
may be able to adapt the method shown here to your needs:

http://gregmaxey.mvps.org/Toggle_Data_Display.htm


chris wrote:
I am trying to understand if it is possible to create a questionnaire where
questions are hidden until a certain answer is given.

E.g. Answer 'No' to question 1, then question 1b opens up that asks a
further question.

I presume some sort of macro would be needed for this? Any help much
appreciated.



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Hide questions in a questionnaire - macro needed?

Chris,

It can be done (with difficulty) and AFAIK, you can't do it without
VBA.

You can create a question in the form of:

Why did the chicken cross the road? Dropdown", and designate a correct
answer e.g., "To get to the other side.

You can create a follow up question in the form of:

But did he say why he wanted to get to the other side? "Dropdown", and
save it as an AutoText entry e.g., "FUQ" (no salaciousness intended).
Note: I bookmarked the Dropdown field in the FUQ as "FUA"

You can insert it at as an AutoText entry and the dropdown is fully
functional and it is fully functional if entered as an AutoText field
e.g., { AUTOTEXT "FUQ" } However, if you nest the AutoText field in a
conditional IF field it fails to display properly.

But did he say why he crossed the road? Missing the dropdown
{IF 1 = "1" "{AutoText "FUQ" }"""" Displays only "But did he say why
...." but not the dropdown.

I am stumped by this and perhaps someone smarter than me has solved
this mystery.

So moving on to VBA.

Again, this was a perplexing challenge. It is easy enough to determine
if the correct answer is given and designate the position that the FUQ
should appear. I used a Select Case method where the case evaluated
was the DropDown field selection. I set a bookmark "FUQ" where the
follow up question would appear.

I stayed with the AutoText entry approach as they are easily inserted
using AutoText. Or and least I thought.

Anytime you use bookmarks to show one thing or another with VBA there
is the problem of redefining the bookmark to suit its intended new
content. If the FUQ was inserted after or before the bookmark and then
the user changed his or her mind about their first answer then you
would quickly have a dog's breakfast on your hands.

http://word.mvps.org/FAQs/MacrosVBA/...AtBookmark.htm

explains this very well.

With that in mind came up with the following code:

Sub OnExitDD1()
Dim oFF As FormFields
Dim oRng As Word.Range
Set oFF = ActiveDocument.FormFields
Select Case
oFF("DropDown1").DropDown.ListEntries(oFF("DropDow n1").DropDown.Value).Name
Case Is = "To get to the other side"
ActiveDocument.Unprotect
Set oRng = ActiveDocument.Bookmarks("FUQ1").Range
oRng.Text = NormalTemplate.AutoTextEntries("FUQ")
ActiveDocument.Bookmarks.Add "FUQ1", oRng
ActiveDocument.Protect wdAllowOnlyFormFields, True
Case Else
ActiveDocument.Unprotect
Set oRng = ActiveDocument.Bookmarks("FUQ1").Range
oRng.Text = ""
ActiveDocument.Bookmarks.Add "FUQ1", oRng
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Select
End Sub

But did he say why he crossed the road? * FORMDROPDOWN **

For some reason (and again I don't understand why). The physical
formfield in the FUQ was converted to text. I suppose that it is due
to using the .Text property of the range. There doesn't seem to be a
..Content property to use. Again perhaps a more experienced programmer
can offer explanation.

Not to be discouraged, I adapted the code to this:

Sub OnExitDropDown1()
Dim oFF As FormFields
Dim oRng As Word.Range
Set oFF = ActiveDocument.FormFields
Select Case
oFF("DropDown1").DropDown.ListEntries(oFF("DropDow n1").DropDown.Value).Name
Case Is = "To get to the other side"
ActiveDocument.Unprotect
Set oRng = ActiveDocument.Bookmarks("FUQ").Range
NormalTemplate.AutoTextEntries("FUQ").Insert oRng
oRng.MoveEndUntil Cset:="?", Count:=wdForward
oRng.MoveEnd wdWord, 2
ActiveDocument.Bookmarks.Add "FUQ", oRng
ActiveDocument.Protect wdAllowOnlyFormFields, True
ActiveDocument.Bookmarks("FUA").Range.FormFields(1 ).Select
Case Else
ActiveDocument.Unprotect
Set oRng = ActiveDocument.Bookmarks("FUQ").Range
oRng.Text = ""
ActiveDocument.Bookmarks.Add "FUQ", oRng
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Select
End Sub

Using the AutoText.Insert method the autotext is inserted with a fully
functional dropdown field. I thin simply expanded oRng forward until I
found the "?" mark then forward again two words (the space and the
formfield). This now but the entire FUQ within oRng and I could
recreate the bookmark.

While I wish that I could determine a more standard approach it appears
to be working.

Note, when I created the AutoText entry FUQ, I bookmarked the formfield
"FUA." You will see in the code that when the user tabs out of the
dropdown answer field that the selection is moved to FUA if it was
created.

HTH.

chris wrote:
Greg - thanks. That's almost it but I want the question to be hidden and only
expand when a certain answer is given (rather than a button to double click).
Do you think that's possible or will I have to use excel?

"Greg Maxey" wrote:

Chris,

If you mean to open up as in display on the screen and print then you
may be able to adapt the method shown here to your needs:

http://gregmaxey.mvps.org/Toggle_Data_Display.htm


chris wrote:
I am trying to understand if it is possible to create a questionnaire where
questions are hidden until a certain answer is given.

E.g. Answer 'No' to question 1, then question 1b opens up that asks a
further question.

I presume some sort of macro would be needed for this? Any help much
appreciated.




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
macro button Jack B Microsoft Word Help 5 July 26th 06 04:22 PM
Form Generaters in Word Graham Beaumont Microsoft Word Help 2 May 17th 06 07:11 PM
FilePrint macro didn't work after all... janice Microsoft Word Help 11 March 28th 06 06:26 PM
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 03:40 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"