Word 2003 - Using a dropdown to show / hide a table

Afternoon

I am trying to create a dropdown list that depending on which entry is selected will show or hide a couple of tables.  I am having to use word as the form is for someone with sight problems otherwise I would use Livecycle etc.  I'm normally not too bad with macros and script but this is stumping me.  What I esentially want is below.

Dropdown list
A
B

Table
1
2

So if option A is selected from the dropdown Table 1 shows and Table 2 disappears, and vice versa.

I'd appreciate some advice on how I go about this please.  I've been looking through the scripts and the individual tables don't have specific names which is also confusing me.

Many thanks in advance

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

I'm assuming your dropdown is a Word form field (not ActiveX, not vba). That field will have a bookmark name in its properties. You also want the property for that field checked to calculate on exit.

You want your table inside an IF Field that tests for the value of the bookmark. If people are going to actually insert anything inside the table, the insertion points also need to be form fields.

Making Forms with Microsoft Word

Start with IF fields that test for the value of your dropdown and simply tell you which option you have.

{ IF { Dropdown1 } = "A" "A is chosen" }{ IF { Dropdown1 } = "B" "B is chosen" }

IF Field

http://office.microsoft.com/en-us/word-help/field-codes-if-field-HP005186163.aspx?CTT=1

Then instead of "A is chosen" and "B is chosen" copy your entire tables into the fields between the quotation marks in the appropriate place.

Note that the document must be "protected for forms" and the user must tab out of the dropdown to activate the test. The field delimiter braces { } cannot be typed, you need to use Ctrl+F9 to insert a pair and the text goes inside the pair. (There are other ways, but that is the easiest.)
Volunteering to "pay forward" the help I've received in the Microsoft user community.


Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com

Legal site: https://addbalance.com

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you for the quick reply, really appreciate it. 

I've set this up and when I avtivate the protection the tables disappear as they should but when selecting the dropdown menu nothing happens.  Does it need some sort of show reference in the script?  I have clicked 'calculate on exit'

This is what I have:

{ IF {Dropdown3} = "A" "Pasted in the 1st table" }{ IF {Dropdown3} = "B" "Pasted in 2nd table" }

Thanks again

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Since Dropdown3 only contains A and B this is all you should need:


{ IF {Dropdown3} = "A" "Your Entire Table A with content""Your Entire Table B with content" }


All the field braces must be entered using CTRL=F9

Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Also, after A or B is selected, you must use the tab key. That will move you to the next form field if there is one, but it also activates the "calculate on exit."
Volunteering to "pay forward" the help I've received in the Microsoft user community.


Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com

Legal site: https://addbalance.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Morning

I'm still struggling.  Is there any chance I could send you the document I'm working on please?  Once I've got this bit working I can use it to complete my form.

Many thanks

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You are welcome to email it to the address below. (You'll have to parse it.)

I am a trial lawyer, though. Do not expect a quick return time. Perhaps a week.
Volunteering to "pay forward" the help I've received in the Microsoft user community.


Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com

Legal site: https://addbalance.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you for the offer.  I've managed to get it working.  One of the brackets I used wasn't created using Ctrl + F9.  Very amateurish of me.

Thanks again for helping me sort this.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Another problem sorry.  Within the tables I've pasted into the IF fields, I have text form fields that I want users to fill in but they aren't showing when the table is presented.  It is possible to show the relevant table depending on the dropdown and then have users fill in the form fields?

Sorry to pester 

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I had believed you could put other form fields inside the table inside the IF Field but was mistaken.

The underlying problem, of which I was unaware, is that if a Form Field is inside an IF field it is not accessible as a form field. This is true even when the document is unprotected. Only when the field codes are displayed does Word see it as a Form Field. Then Word treats it as a Form Field. You can double-click on it to get the properties.

In one of my forms I use on-exit macros that make changes in the document including enabling fill-in on other text form fields (that are otherwise invisible to the user when the document is protected). These could probably insert a table with form fields using AutoText to hold the table. Such a macro needs to unprotect the form, make the change, reprotect the form, and go to the appropriate field.

This is more programming than I would want to undertake without a powerful reason, though.

Should you choose to undertake it, though, here is the code to protect and unprotect a password protected form. You would call these procedures from your on-exit macro.

Sub UnProtectForm()
    Dim sPass as String
    With ActiveDocument
        sPass = "MyPassword"
        If .ProtectionType <> wdNoProtection Then .Unprotect (sPass)
        ' End If
    End With
End Sub

Sub ProtectForm()
     Dim sPass as String
     With ActiveDocument
        sPass = "MyPassword"
        If .ProtectionType = wdNoProtection Then .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPass
            ' End If
    End With
End Sub


Volunteering to "pay forward" the help I've received in the Microsoft user community.


Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com

Legal site: https://addbalance.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Since Charles has brought you this far, we might as well go the full course ;-)


1. Define TableA with your appropriate formfields, select it, press ALT+F3 and save it as an AutoText entry named TableA. 


2. Define TableB with your appropriate formfields, select it, press ALT+F3 and save it as an AutoText entry named TableB.


3. Delete tables A and B from the document.


4. Add a bookmark where table A or B should appear.  Name it bmTableRange.


5.  Add the following code to a standard code module in the document.  If required, see: http://gregmaxey.mvps.org/word_tip_pages/installing_employing_macros.html for instructions to employ the VBA code provided:


Sub InsertTable()
Dim oRng As Word.Range
With ActiveDocument
  If .ProtectionType = wdAllowOnlyFormFields Then
    .Unprotect
    Set oRng = ActiveDocument.Bookmarks("bmTableRange").Range
    If oRng.Tables.Count = 1 Then oRng.Tables(1).Delete
    If .FormFields("Dropdown3").Result = "A" Then
      Set oRng = .AttachedTemplate.AutoTextEntries("TableA").Insert(Where:=oRng, RichText:="True")
    ElseIf .FormFields("Dropdown1").Result = "B" Then
      Set oRng = .AttachedTemplate.AutoTextEntries("TableB").Insert(Where:=oRng, RichText:="True")
    End If
    .Bookmarks.Add "bmTableRange", oRng
    .Protect wdAllowOnlyFormFields, True
  End If
End With

End Sub


6. Set an InsertTable to run OnExit from your Dropdown3 field.  You must have another valid field following dropdown3 to tab or click into so the exit event fires.


7.  Lock the form and toggle between "A" and "B" and exit the field.



Greg Maxey
***
Death smiles at us all, but all a man can do is smile back.


For more help with Word visit:
http://gregmaxey.com/word_tips.html

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

 
 

Question Info


Last updated January 11, 2024 Views 3,845 Applies to: