PDA

View Full Version : Checkbox values based on mail merge values



dattagal
03-06-2007, 09:59 AM
Hi everyone

If an answer to my dilemma has already been posted, I failed to find it so I would be forever in your debt if you could help me.

This is something that comes up often in mail merges that I do.

We have a "form" (a Word document with tables and such) with which we merge data from Excel. There are "checkmark boxes" (little squares - not actual checkmark boxes).

I would like to have the boxes show "checked" (like showing a checkmark in the little square) in response to a merge field.

For example, if the CurrentlyEnrolled merge field for a particular record says yes, then I want the "YES" check box under Enrolled to have a check mark in it. If the next record is a "No" for CurrentlyEnrolled, then I want the box left "unchecked".

Can I do this?

fumei
03-06-2007, 10:41 AM
Not if you have them just as little squares. If you had them as actual checkboxes, I don't see why not.

dattagal
03-06-2007, 10:58 AM
What if I changed them to an actual check box? How would I do it then?

mdmackillop
03-06-2007, 06:08 PM
Here's some code I have for extracting mergefield information. This could be adapted to set form values etc.
Sub ShowDataInfo()

Dim Rec As Integer
Dim Title As String
Dim DataF As Variant, DRecord As String

Title = ActiveDocument.Name
Rec = 0
DRecord = "DataSource - " & Documents(Title).MailMerge.DataSource.Name & vbCr _
& "DataFields" & vbCr
For Each DataF In _
Documents(Title).MailMerge.DataSource.DataFields
Rec = Rec + 1
If DataF.Value <> "" Then DRecord = DRecord & _
Rec & ". " & DataF.Value & vbCr
Next DataF

MsgBox DRecord

End Sub

fumei
03-06-2007, 06:29 PM
Following that,
If ActiveDocument.MailMerge.DataSource. _
DataFields("CurrentlyEnrolled").Value = True Then
ActiveDocument.FormFields("CurrentlyEnrolled") _
.CheckBox.Value = True
Else
ActiveDocument.FormFields("CurrentlyEnrolled") _
.CheckBox.Value = False
End If

Better yet, if they were both Boolean...
ActiveDocument.FormFields("CurrentlyEnrolled") _
.CheckBox.Value = _
ActiveDocument.MailMerge.DataSource. _
DataFields("CurrentlyEnrolled").Valueand simply make them equivalent.

Note that to check, or uncheck, a formfield like this you do NOT, repeat NOT, have to protect the document for forms.

Formfields check values can be switched on or off by code directly without protection. There may be value in that, because with protection not invoked, the user will not be able to check it. Only your code would be able.