Are your fields
- legacy form fields (those designed for protected documents)?
- or the new content control fields?
- or active X controls?
You want legacy form fields.
You want an on-exit macro for the checkbox to enable the drop-down.
What follows is code that I use in a protected document to enable/disable a field depending on the value of a checkbox.
Code:
Option Explicit
Public sPass
' Module and Project Written by Charles Kyle Kenyon
' May 2001, Copyright 2001 All rights reserved
Sub AutoNew()
AutoOpen
End Sub
Sub AutoOpen()
SetDocumentVariablePassword
sPass = ActiveDocument.Variables("FormPassWord")
LockDocForForms 'Lock this form so formfields will work
GoToStartingField 'If set for particular case, goto witness info
End Sub
Private Sub LockDocForForms()
'Locks Document or Template for Forms upon opening or creation
If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:=sPass
End If
End Sub
Private Sub GoToStartingField()
' Checks to see if form has been modified for a particular _
defendant. If it has, then start with Witness name, _
otherwise, start with County name
If ActiveDocument.FormFields("DefName").Result = "DEFENDANT'S NAME?" Then
ActiveDocument.FormFields("County").Select
Else
ActiveDocument.FormFields("WitName").Select
End If
End Sub
Private Sub SetDocumentVariablePassword()
Dim num As Integer, aVar As Variable
For Each aVar In ActiveDocument.Variables
If aVar.Name = "FormPassWord" Then num = aVar.Index 'End If
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add Name:="FormPassWord", Value:="GF126"
Else
ActiveDocument.Variables(num).Value = "GF126"
End If
End Sub
Public Sub ProtectSubpoenaForForms()
On Error GoTo NotSubpoena
With ActiveDocument
sPass = .Variables("FormPassWord") 'will trip error message if not set
If .ProtectionType = wdNoProtection Then .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPass
' End If
End With
On Error GoTo 0
End
NotSubpoena:
MsgBox "This is not a subpoena form based on the right template!", vbExclamation, "Oh! Oh! Wrong Document for this macro!"
End Sub
Sub DucesTecum()
'
' DucesTecum Macro
' OnExit macro for DucesTecum Checkbox
' "&chr(10)&"Macro recorded 05/16/2001 by Charles Kyle Kenyon
'
Dim strBringWith As String, rRange As Range
With ActiveDocument
UnProtectSubpoena 'subroutine below
Set rRange = .Bookmarks("YouBringYes").Range
'Save result of form field
strBringWith = .FormFields("BringWhat").Result
If .FormFields("chkDucesTecum").CheckBox.Value _
= True Then
.FormFields("DucesTecumTitle").TextInput.EditType _
Type:=wdRegularText, Default:=" Duces Tecum "
If strBringWith = "" Then strBringWith = _
"Bring what?" 'End If
.FormFields("BringWhat").TextInput.EditType _
Type:=wdRegularText, Default:=strBringWith, _
Enabled:=True
rRange.Font.DoubleStrikeThrough = False
rRange.Font.Bold = True
.FormFields("BringWhat").Select
Else
.FormFields("DucesTecumTitle").TextInput.EditType _
Type:=wdRegularText, Default:=" ", Enabled:=False
.FormFields("BringWhat").TextInput.EditType _
Type:=wdRegularText, Default:="", Enabled:=False
rRange.Font.DoubleStrikeThrough = True
rRange.Font.Bold = False
.FormFields("chkThirdParty").Select
End If
.Protect wdAllowOnlyFormFields, True, sPass
End With
End Sub
Sub ThirdParty()
'
' ThirdParty Macro
' OnExit Macro for Third-Party Checkbox
' "&chr(10)&"Macro written 05/16/2001 by Charles Kyle Kenyon
'
Dim rRange As Range
With ActiveDocument
UnProtectSubpoena 'subroutine below
Set rRange = .Bookmarks("ThirdPartyLanguage").Range
rRange.Font.DoubleStrikeThrough = _
Not .FormFields("chkThirdParty").CheckBox.Value
rRange.Font.Bold = _
.FormFields("chkThirdParty").CheckBox.Value
.Protect wdAllowOnlyFormFields, True, sPass
End With
End Sub
Sub UnprotectSubpoenaForm() 'For Menu
MsgBox "The password to unprotect this document is " _
& ActiveDocument.Variables("FormPassWord") & "." & vbCrLf _
& "You must use the same password if you reprotect it, otherwise the form will not work. Please write it down.", vbExclamation, "Subpoena Form Password Information"
UnProtectSubpoena
End Sub
Private Sub UnProtectSubpoena() 'Subroutine for other procedures
With ActiveDocument
sPass = .Variables("FormPassWord")
If .ProtectionType <> wdNoProtection Then .Unprotect (sPass)
' End If
End With
End Sub
This may be more than you need, but as you can see, I wrote this more than ten years ago. I don't code for this often.
It includes code for:
- using a document variable for the password
- unprotecting the document using the password
- enabling/disabling a named field
- altering formatting
- and reprotecting a document without resetting field contents.
The procedures set as on-exit macros are labelled as such in comments. I hope this will help.