Valid Property

Microsoft Word Visual Basic

expression.Valid

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

For the CheckBox, DropDown, and TextInput objects, use the Type property of the FormField object to determine the type of form field (wdFieldFormCheckBox, wdFieldFormDropDown, or wdFieldFormTextInput) before applying the CheckBox , DropDown , or TextInput property. This precaution ensures that the FormField object is the expected type. If the first form field in the active document is a check box, the following example selects the check box.

If ActiveDocument.FormFields(1).Type = wdFieldFormCheckBox Then
    ActiveDocument.FormFields(1).CheckBox.Valid = True
End If
		

Example

ShowAs it applies to the CheckBox object.

This example adds a text form field at the insertion point. Because myFormField is a text input field and not a check box, the message box displays "False."

Selection.Collapse Direction:=wdCollapseStart
Set myFormField = ActiveDocument.FormFields.Add(Range:= _
    Selection.Range, Type:=wdFieldFormTextInput)
MsgBox myFormField.CheckBox.Valid
				

ShowAs it applies to the TextInput object.

This example determines whether the first form field in the active document is a text form field. If the Valid property is True, the contents of the text form field are changed to "Hello."

If ActiveDocument.FormFields(1).TextInput.Valid = True Then
    ActiveDocument.FormFields(1).Result = "Hello"
End If
				

ShowAs it applies to the CustomLabel object.

If the settings for the custom label named "My Labels" are valid, this example creates a new document of labels using the My Labels settings.

addr = "James Allard" & vbCr & "123 Main St." & vbCr _
    & "Seattle, WA 98040"
If Application.MailingLabel.CustomLabels("My Labels") _
        .Valid = True Then
    Application.MailingLabel.CreateNewDocument _
        Name:="My Labels", Address:=addr
End If