ValidationRules.Add Method (Visio)
Adds a new, empty ValidationRule object to the ValidationRules collection of the document.
Version Information
Version Added: Visio 2010
Syntax
expression .Add(NameU)
expression A variable that represents a ValidationRules object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
NameU |
Required |
String |
The universal name to assign to the new validation rule. |
Return Value
ValidationRule
Remarks
If the NameU parameter is not a valid string, Microsoft Visio returns an Invalid Parameter error.
The default property values of the new validation rule are as follows: Category = [empty]; Description = "Unknown"; FilterExpression = [empty]; Ignored = False; TargetType = visRuleTargetShape; TestExpression = [empty].
Example
The following sample code is based on code provided by: David Parker
The following Visual Basic for Applications (VBA) example shows how to use the Add method to add a new validation rule named "UngluedConnector" to an existing validation rule set named "Fault Tree Analysis" in the active document.
Public Sub Add_Example()
Dim vsoValidationRule As Visio.ValidationRule
Dim vsoValidationRuleSet As Visio.ValidationRuleSet
Dim strValidationRuleSetNameU As String
Dim strValidationRuleNameU As String
strValidationRuleSetNameU = "Fault Tree Analysis"
strValidationRuleNameU = "UngluedConnector"
Set vsoValidationRuleSet = ActiveDocument.Validation.RuleSets(strValidationRuleSetNameU)
Set vsoValidationRule = vsoValidationRuleSet.Rules.Add(strValidationRuleNameU)
End Sub