Including Check Boxes on an MS Word Merge Document
This article explain how to use the data stored within SmartSimple to determine whether or not a Check Box on an MS Word Merge document is checked.
- The same principles can be used for many other advanced controls of MS Word Merge documents based on underlying SmartSimple data.
You cannot merge information directly into a Check Box Form Field on the MS Word document to make it checked or unchecked. Instead it can be done as follows:
- Create a source Text Form Field on the MS Word document to store the value that determines whether or not the Check Box should be checked.
- Create the target Check Box Form Field on the MS Word document
- Create a VB Script that runs automatically when the document opens and does the following:
- Reads the value in the source Text Form Field and changes the value of the Check Box Form Field to True (which will make it checked), if the source value dictates that it should be checked.
- Deletes the source Text Form Field
The following example demonstrates how to check a check box on the MS Word document if the source field within SmartSimple has "CheckMe" as the stored value.
Note: these instructions are for MS Word 2003. If you are using a different version the steps may vary. Please consult MS Word Help for assistance.
MS Word Template
On the MS Word Template document create a Text Form Field. Double-click on the field and enter the name source in the “Bookmark” field.
- The source field is where the merge data will be stored. When the MS Word Merge document is opened, a macro will use this value in this field to determine whether or not the associated checkbox should be checked. The field will then be deleted by the macro.
Next create the Check Box Form Field, double-click on it and enter the name target in the “Bookmark” field. Be sure that you have created a “Check Box Form Field”, not just a Check Box
Finally open the Tools menu > Macro > Visual Basic Editor Double-click on "ThisDocument" on the left-hand pane and then add the following script:
Private Sub Document_Open() '--- Exit if an error is encountered On Error GoTo ExitSub '--- define variables Dim source As Bookmark Set source = ActiveDocument.Bookmarks("source") Dim target As CheckBox Set target = ActiveDocument.FormFields("target").CheckBox '--- check the source text and tick the associated target checkbox if appropriate If (source.Range.Text = "CheckMe") Then target.Value = True '--- Delete the source field source.Range.Delete ExitSub: End Sub
NOTE: the Document_Open subroutine is NOT executed automatically in MS Word 2002 and earlier. If using earlier versions of Word replace the line:
- Private Sub Document_Open()
- Sub AutoOpen()
MS Word Merge Custom Field
On the MS Word Merge Custom Field within SmartSimple you should assign the Custom Field that determines whether or not the check box will be checked to the source Text Form Field.
Do not assign anything to the target Check Box Form Field.
The user who performs the MS Word Merge must have macros enabled for MS Word or it will not run.
- Macros can be enabled via the Tools menu > Macros > Security
- The setting can be set to either Medium or Low. Medium is recommended, which means the user will have to agree to allow the macro to run each time the document is opened.
When you are creating the original MS Word Merge document you will need to disable macros while you work on the document. Otherwise the source “Text Form Fields” will be deleted by the macro each time you open the document. You should only allow the macro to run when you have actually created the document via the MS Word Merge in SmartSimple.
The "On Error GoTo ExitSub" command in the script is very important. Once the document has been opened the first time the macro deletes all the source Text Form Fields. Any time the document is opened subsequently the macro will try to reference these fields, and since they no longer exist the command will fail and the macro will exit.
Hint: You may want to exclude the part of the macro that deletes the source fields while you are working on the document. This will allow you to see if the source fields are populating with the information you would expect to see.
To set up a Word merge:
- Step 1 - Create the MS Word document that will be used as the template.
- Step 2 - Upload the Word document to a SmartFolder.
- Step 3 - Create a Special - MS Word Merge custom field.
Advanced Word Merge Features Include:
- Exporting List View Results to Microsoft Word
- Uploading a MS Word Merge Document to a Custom Field
- Including Tables in a Word Merge Document
- Using ReportProperty with a Word Merge Document
- Including Check Boxes on an MS Word Merge Document
- Including XML on an MS Word Merge Document
- Using Conditional Logic on a MS Word Merge Document