April 9, 2024
Contribute to the Microsoft 365 and Office forum!
Click here to learn more 💡
May 10, 2024
Word Forum Top Contributors:
Word 2003 - Using a dropdown to show / hide a table
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
Report abuse
Thank you.
Reported content has been submitted
* Please try a lower page number.
* Please enter only numbers.
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.)
Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com
Legal site: https://addbalance.com
Report abuse
Thank you.
Reported content has been submitted
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.
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
Report abuse
Thank you.
Reported content has been submitted
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
***
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
Report abuse
Thank you.
Reported content has been submitted
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.
Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com
Legal site: https://addbalance.com
Report abuse
Thank you.
Reported content has been submitted
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'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
Report abuse
Thank you.
Reported content has been submitted
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 am a trial lawyer, though. Do not expect a quick return time. Perhaps a week.
Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com
Legal site: https://addbalance.com
Report abuse
Thank you.
Reported content has been submitted
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.
Thanks again for helping me sort this.
Report abuse
Thank you.
Reported content has been submitted
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.
Sorry to pester
Report abuse
Thank you.
Reported content has been submitted
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.
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
Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com
Legal site: https://addbalance.com
Report abuse
Thank you.
Reported content has been submitted
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.
***
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
Report abuse
Thank you.
Reported content has been submitted
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.
Question Info
Last updated January 11, 2024 Views 3,845 Applies to: