PDA

View Full Version : Content Controls - Usable form using Radio Buttons



Cheesecube
04-19-2020, 10:03 PM
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?

Cheesecube
04-20-2020, 02:09 AM
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

macropod
04-20-2020, 02:14 AM
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/showthread.php?40406-Extracting-Word-form-Data-and-exporting-to-Excel-spreadsheet&p=257696&viewfull=1#post257696

gmayor
04-20-2020, 02:30 AM
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

macropod
04-20-2020, 04:10 AM
Cheescube: Kindly post post multiple threads on essentially the same topic. I have merged these two threads.

gmaxey
04-20-2020, 08:05 AM
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

Cheesecube
04-20-2020, 08:57 PM
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

gmayor
04-21-2020, 12:46 AM
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.

gmaxey
04-21-2020, 11:13 AM
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


26408 (https://gregmaxey.com/word_tip_pages/content_control_tools.html)

Cheesecube
04-21-2020, 07:32 PM
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


26408 (https://gregmaxey.com/word_tip_pages/content_control_tools.html)

Would it be possible to modify the content control titles to use something more meaningful? E.g. ContractForm, PackageDetails, Exemptions, PromoCodes

gmaxey
04-23-2020, 10:35 AM
If you map the CCs by Tag e.g., A1, A2, A3 ... B1, B2, B3 ... etc. Then you can title them anyway you want.

Cheesecube
04-23-2020, 08:33 PM
If you map the CCs by Tag e.g., A1, A2, A3 ... B1, B2, B3 ... etc. Then you can title them anyway you want.




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?

gmaxey
04-24-2020, 07:49 AM
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:

26434

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.

tree111a
03-31-2023, 12:16 PM
Hello I am getting notification of trojan multiverze when downloading content control tools from https://gregmaxey.com/word_tip_pages/content_control_tools.html

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

gmaxey
03-31-2023, 12:36 PM
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.

tree111a
03-31-2023, 01:06 PM
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?

gmaxey
03-31-2023, 01:50 PM
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