Valid Property

Microsoft Word Visual Basic

Show All

Valid Property

       

CheckBox, DropDown, and TextInput objects: True if the specified form field object is a valid check box form field. Read-only Boolean.

CustomLabel object: True if the various properties (for example, Height, Width, and NumberDown) for the specified custom label work together to produce a valid mailing label. Read-only Boolean.

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

As 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

As 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

As 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