Programatically locking fields in Word 2010

I played with VBA many years ago and I don't remember much so I need your help. I have an end-user who developed a form in Word 2010 that is full of text fields and checkboxes. It is currently "protected" from any changes and the issue we are having is that the end-user wants the form to "lock" (not allowing any changes to that file) after we fill in the fields and save it.

I did some research and I understand that we could set the document's code to "fire" after an event (OnSave) so that when the user saves the document, the entire document would be locked from further changes (we want to permanently archive it) and we did consider saving as PDF but we hire blind employees and PDF are not "accessible" to our blind employees, so we are forced to save it as a Word file.

Assuming your "text fields and checkboxes" are formfields, you could use a macro like the following, in the form or it's template:

Code:

Private Sub Document_Close()
Dim FmFld As FormField, bComp As Boolean, bSaved As Boolean
With ActiveDocument
bSaved = .Saved
bComp = True
For Each FmFld In .FormFields
With FmFld
If .Type = wdFieldFormTextInput Then
If Trim(.Result) = vbNullString Then
bComp = False
MsgBox "Please complete all the items"
ActiveDocument.Reload
Exit Sub
End If
ElseIf .Type = wdFieldFormDropDown Then
If .DropDown.Value = .DropDown.Default Then
bComp = False
MsgBox "Please complete all the items"
ActiveDocument.Reload
Exit Sub
End If
End If
End With
Next
If bComp = True Then
For Each FmFld In .FormFields
FmFld.Enabled = False
Next
End If
If bSaved <> .Saved Then .Save
End With
End Sub

The test for Dropdown formfields assumes the default value (which might be a blank or text asking for a selection to be made) is not valid.

The problem you'll have with both checkboxes and Dropdown formfields that have valid default values is that there is no reliable way of telling whether those values are 'correct'

In that case, you might prefer a less intrusive version. This one gives no prompts and, instead, simply checks whether all the textboxes & dropdowns have been updated. If so, the form is locked.

Code:

Private Sub Document_Close()
Dim FmFld As FormField, bSaved As Boolean
With ActiveDocument
bSaved = .Saved
For Each FmFld In .FormFields
With FmFld
If .Type = wdFieldFormTextInput Then
If Trim(.Result) = vbNullString Then Exit Sub
ElseIf .Type = wdFieldFormDropDown Then
If .DropDown.Value = .DropDown.Default Then Exit Sub
End If
End With
Next
For Each FmFld In .FormFields
FmFld.Enabled = False
Next
If bSaved <> .Saved Then .Save
End With
End Sub