Using drop down menu in word to display the correct table

Anonymous
2022-04-08T10:03:01+00:00

Hello Everyone,

I am currently working on creating a form for requests with Microsoft word 365.

In this form I want at some point to give different options using a drop down menu. Then based on the option they have choose, I want a specific predefined table to appear that they can fill in.

So for example they will have a drop down menu to give the options, Gap fill, Matching and Ordening:

Then if they choose Gap fill I want to table for gap fill to appear, if they chosen Matching, the table for matching needs to appear, ect.

The appearing tables should still be editable.

So far I have managed to create the drop down menu and I created this tables in such way that they are fill in tables. But how can I like which table is displayed based on the drop down menu? And this all should be displayed in Word.

The alternative would be to use the quick parts gallery and add a Building block content control. However when I then protect the word file (with start enforcing protection), one can no longer choose these quickparts. even it I don't protect the section in which the building block content control is added.

Microsoft 365 and Office | Word | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2022-04-08T17:19:58+00:00

    The alternative, I've found, is to use only legacy form fields instead of content controls, and to apply the "Filling in forms" type of restriction. Each menu dropdown needs to have the "exit macro" item in the Properties dialog set to run a macro like the following. It assumes that the "bookmark name" of each menu dropdown is "Menu" followed by a unique number or other text, and below the menu dropdown there is a bookmark whose name is "BB" followed by the same number or text. These items, along with the building blocks that contain the tables, must be saved in a macro-enabled template (*.dotm), and with the restriction turned on in the template.

    Instructions for installing macro code in your template may be found at https://www.gmayor.com/installing_macro.htm .

    Image

    Option Explicit 
    
    Sub InsertBuildingBlock() 
    
        Dim MenuName As String 
    
        Dim BkMkName As String 
    
        Dim rgBB As Range 
    
        Dim testbb As BuildingBlock 
    
        With ActiveDocument 
    
            MenuName = Selection.Bookmarks(1).Name 
    
            BkMkName = Replace(MenuName, "Menu", "BB") 
    
            .Unprotect 
    
            ' trigger an error if the named building block 
    
            ' doesn't exist 
    
            On Error GoTo badBB 
    
            Set testbb = .AttachedTemplate.BuildingBlockEntries(.FormFields(MenuName).Result) 
    
            On Error GoTo Reprotect 
    
            Set rgBB = .Bookmarks(BkMkName).Range 
    
            If rgBB.Tables.Count > 0 Then 
    
                ' if there is already a table in the bookmark, 
    
                ' delete it and re-add the bookmark; otherwise 
    
                ' the new table would be added after the existing one 
    
                rgBB.Tables(1).Delete 
    
                .Bookmarks.Add Name:=BkMkName, Range:=rgBB 
    
            End If 
    
            Set rgBB = testbb.Insert(Where:=rgBB, RichText:=True) 
    
            .Bookmarks.Add Name:=BkMkName, Range:=rgBB 
    
        End With 
    
    Reprotect: 
    
            ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True 
    
        Exit Sub 
    
    badBB: 
    
        MsgBox "Building block '" & ActiveDocument.FormFields(MenuName).Result & _ 
    
            "' does not exist in this template." 
    
        GoTo Reprotect 
    
    End Sub 
    

    The lines in the code that start with an apostrophe are comments, which explain what happens as the statements after them will do.

    This macro is not perfect. For example, if existing tables contain form fields, sometimes the code won't allow the cursor to move from the menu to those other fields. If this is a problem you see when you adapt the solution to your own template, send a copy of your template to me at the address shown in https://jay-freedman.info/contact/contact.htm and I'll try to make it work.

    1 person found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-04-08T12:01:10+00:00

    There are two ways to go about this.

    The simpler way is to use a building block content control as you have already tried, and omitting the dropdown menu. However, do not use the Restrict Editing type of protection. Instead, select the entire document and then click the Group button on the Developer ribbon (to the right of the content controls) and choose Group from its menu. This will protect all areas outside of the content controls while permitting the operation of the controls themselves.

    An important note about this method: The form must be saved as a template, not a document, and the building blocks must be saved in that template. (Building blocks cannot be saved in documents, only in templates.) Also, if you have dropdowns and other controls in the tables that are in building blocks, those must also be content controls and not legacy form fields (which won't work without forms protection).

    The other method involves keeping the dropdown menu, not using building block content controls, and instead writing a macro to insert the correct building block when the user makes a choice in the menu. If you are interested in this method, post back for instructions.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2022-04-08T12:10:04+00:00

    I tried the group method, unfortunately it is then still easy to unlock the form. that is why restricted editing was preferred.

    I am however interested in the method using macro's, but I have no background in creating those.

    0 comments No comments
  3. Charles Kenyon 160K Reputation points Volunteer Moderator
    2022-04-08T16:16:52+00:00

    First, use the group method with the Building Blocks Content Control.

    Then apply the Restrict Editing and use the No Changes with exceptions restriction. Mark your Content Control as an exception.

    Note that the password protection provided by this is very weak. Personally, I would just use the Group method and train people to not mess with it.

    1 person found this answer helpful.
    0 comments No comments