Consulting

Results 1 to 17 of 17

Thread: Content Controls - Usable form using Radio Buttons

  1. #1

    Lightbulb Content Controls - Usable form using Radio Buttons

    Hi, I have a question about designing a usable form in Word using Radio Buttons

    I have attached a document demonstrating my intended functionality

    - How do I turn this Microsoft Word document into a usable form with Content Controls?
    - How do I extract the form data after the user has entered in the choice? Preferably using Document.ContentControls(i).Value

    Please include step-by-step directions on how to achieve this

    Preferably the solution should use Content Controls and minimal VBA scripting

    Edit: I need a solution that extracts data from radio buttons without using VBA (e.g. XML Tags with Content Controls), is this possible?
    Attached Files Attached Files
    Last edited by Cheesecube; 04-19-2020 at 11:28 PM.

  2. #2

    Lightbulb MS Word - Simulate Radio Buttons using Checkboxes

    Hi, I need the user to pick only one choice from a series of options.

    However, for business process automation purposes with an external program, I need to use Content Control form elements. It so happens that Radio Buttons are not included in Content Controls. There are too many options for a dropdown list to be user-friendly.

    How do I simulate radio button behaviour using checkboxes? I.e. when one option is picked, the rest of the options within the set are greyed out and cannot be picked.

    There might be several sets of choices, each set can only have one choice that can be picked.

    See attached file as example
    Attached Files Attached Files
    Last edited by Cheesecube; 04-20-2020 at 02:38 AM.

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Why are you using radio buttons in your example instead of a dropdown, for example? Exporting dropdown results is far simpler. For code to extract data from a document using content controls, see: http://www.vbaexpress.com/forum/show...l=1#post257696
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    You can use a macro to uncheck the others in the group see attached which has two groups of 4. You can modify the code to use the checkbox titles you have used rather than those in the macro, and add groups/controls as required.

    You could also use a listbox instead of the check boxes (also attached) with the options required for that group and that wouldn't need macros.

    You may find https://www.gmayor.com/insert_content_control_addin.htm useful
    Attached Files Attached Files
    Last edited by gmayor; 04-20-2020 at 02:51 AM.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cheescube: Kindly post post multiple threads on essentially the same topic. I have merged these two threads.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Graham,

    If you map the CCs in your RadioButtonsExample document, you can greatly simplify the coding:

    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
    Dim oXMLPart As CustomXMLPart
    Dim oNode As CustomXMLNode
      Set oXMLPart = ContentControl.XMLMapping.CustomXMLPart
      If Content = True Then
        For Each oNode In oXMLPart.DocumentElement.ChildNodes
          'The first character of the title and node name identifies the set (i.e., "A" or "B")
          If Left(oNode.BaseName, 1) = Left(ContentControl.Title, 1) Then
            If Not oNode.BaseName = ContentControl.Title Then
              oNode.Text = "false"
            End If
          End If
        Next
      End If
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    Quote Originally Posted by gmaxey View Post
    Graham,

    If you map the CCs in your RadioButtonsExample document, you can greatly simplify the coding:

    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
    Dim oXMLPart As CustomXMLPart
    Dim oNode As CustomXMLNode
      Set oXMLPart = ContentControl.XMLMapping.CustomXMLPart
      If Content = True Then
        For Each oNode In oXMLPart.DocumentElement.ChildNodes
          'The first character of the title and node name identifies the set (i.e., "A" or "B")
          If Left(oNode.BaseName, 1) = Left(ContentControl.Title, 1) Then
            If Not oNode.BaseName = ContentControl.Title Then
              oNode.Text = "false"
            End If
          End If
        Next
      End If
    lbl_Exit:
      Exit Sub
    End Sub

    - Hi, kindly explain how this code works
    - How to group the checkboxes together
    - How to manage the different groups of checkboxes

    Thanks

  8. #8
    While Greg's suggestion is more elegant, I am sure he would be the first to agree that it is better to learn to walk before you start to run - and for forms you supply to third parties to fill, it is preferable to use list boxes to select options, as they don't require the use of macros, that you cannot ensure those others will allow to run. You can have as many list boxes as you have groups.
    Attached Files Attached Files
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  9. #9
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    The content controls would be grouped as Graham provided in his RadioButtonsExample.docm file. Where he had two groups with CCs titled A1, A2, A3 and A4 (group 1) and B1, B2, B3 and B4 (group). The content controls are then mapped to a customXMLPart. You can using my CC Tools AddIn ("InstaMap" feature) to do that:

    https://gregmaxey.com/word_tip_pages/content_control_tools.html


    RadioButtons Using Document Before Store Update.docm
    Greg

    Visit my website: http://gregmaxey.com

  10. #10
    Quote Originally Posted by gmaxey View Post
    The content controls would be grouped as Graham provided in his RadioButtonsExample.docm file. Where he had two groups with CCs titled A1, A2, A3 and A4 (group 1) and B1, B2, B3 and B4 (group). The content controls are then mapped to a customXMLPart. You can using my CC Tools AddIn ("InstaMap" feature) to do that:

    https://gregmaxey.com/word_tip_pages/content_control_tools.html


    RadioButtons Using Document Before Store Update.docm
    Would it be possible to modify the content control titles to use something more meaningful? E.g. ContractForm, PackageDetails, Exemptions, PromoCodes

  11. #11
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    If you map the CCs by Tag e.g., A1, A2, A3 ... B1, B2, B3 ... etc. Then you can title them anyway you want.
    Greg

    Visit my website: http://gregmaxey.com

  12. #12
    Quote Originally Posted by gmaxey View Post
    If you map the CCs by Tag e.g., A1, A2, A3 ... B1, B2, B3 ... etc. Then you can title them anyway you want.
    Quote Originally Posted by gmaxey View Post
    Private Sub Document_ContentControlBeforeStoreUpdate(ByVal ContentControl As ContentControl, Content As String)
    Dim oXMLPart As CustomXMLPart
    Dim oNode As CustomXMLNode
      Set oXMLPart = ContentControl.XMLMapping.CustomXMLPart
      If Content = True Then
        For Each oNode In oXMLPart.DocumentElement.ChildNodes
          'The first character of the title and node name identifies the set (i.e., "A" or "B")
          If Left(oNode.BaseName, 1) = Left(ContentControl.Title, 1) Then
            If Not oNode.BaseName = ContentControl.Title Then
              oNode.Text = "false"
            End If
          End If
        Next
      End If
    lbl_Exit:
      Exit Sub
    End Sub
    Hi, kindly walk through this code... I see that the code refers to the first letter of Title to match and group together the checkboxes.

    Which part of the code uses the content control Tags to achieve the grouping functionality?

  13. #13
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    In the example document I provided, the CCs where titled and tagged with A1, A2, A3 ... B1, B2, B3 ... etc.

    The CustomXMLPart (the XML) looks like this:

    2020-04-24_10-44-00.jpg

    So the first character of the Node names "A" or "B" define the option button group name e.g., Group "A" or Group "B". You can change "Title" in the code above to "Tag" if you want to later change the titles of you CCs to something more meaningful.
    Greg

    Visit my website: http://gregmaxey.com

  14. #14
    VBAX Newbie
    Joined
    Mar 2023
    Posts
    2
    Location
    Hello I am getting notification of trojan multiverze when downloading content control tools from https://gregmaxey.com/word_tip_pages...rol_tools.html

    Can you please send me any safer option to download this plugin?

  15. #15
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    As best I can tell, it is a Windows Defender false positive. I use the add-in all the time, it has been downloaded thousands of times. I routinely scan it with Malware Bytes. It is clean to the best of my knowledge. If it were me, I would turn off Windows Defender and download it.
    Greg

    Visit my website: http://gregmaxey.com

  16. #16
    VBAX Newbie
    Joined
    Mar 2023
    Posts
    2
    Location
    Thanks Greg for your response. Even after disabling Windows Defender, I am not able to download through zip folder. Is it possible for you to attach the dotm file without zip folder?

  17. #17
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    If you want to send me website feedback, I can send the file to you as an attachment to my reply.

    https://gregmaxey.com/website_feedback_contact.html
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •