Class FormatConditions (Access VBA)

The FormatConditions collection represents the collection of conditional formats for a combo box or text box control. Each format is represented by a FormatCondition object. To use a FormatConditions class variable it first needs to be instantiated, for example

Add

You can use the Add method to add a conditional format as a FormatCondition object to the FormatConditions collection of a combo box or text box control.

You can use the Delete method of the FormatConditions collection to delete an existing FormatConditions collection from a combo box or text box control.

Add (Type, Operator, Expression1, Expression2)


Dim fcd As FormatCondition
Set fcd = CreateForm.Controls(1).FormatConditions.Add(Type:=acDataBar)

Arguments

The following argument is required

Type (AcFormatConditionType) - An AcFormatConditionType constant that specifies the type of format condition to be added.


Possible values are

acDataBar The conditional format is displayed as a data bar.
acExpression The conditional format is based on an expression.
acFieldHasFocus The conditional format is based on the value of the control that has focus on a form.
acFieldValue The conditional format is based on values in the selected control.

Optional arguments

The following arguments are optional

Operator (AcFormatConditionOperator) - An AcFormatConditionOperator constant that specifies the operator. If the Type argument is acExpression, the Operator argument is ignored. If you leave this argument blank, the default constant (acBetween) is assumed.


Possible values are

acBetween The value must be between the values specified by the Expression1 and Expression2 arguments.
acEqual The value must equal to the value specified by the Expression1 argument.
acGreaterThan The value must be greater than the value specified by the Expression1 argument.
acGreaterThanOrEqual The value must be greater than or equal to the value specified by the Expression1 argument.
acLessThan The value must be less than the value specified by the Expression1 argument.
acLessThanOrEqual The value must be less than or equal to the value specified by the Expression1 argument.
acNotBetween The value must not be between the values specified by the Expression1 and Expression2 arguments.
acNotEqual The value must not be equal to the value specified by the Expression1 argument.

Expression1 - A value or expression associated with the first part of the conditional format. Can be a constant or a string value

Expression2 (AcFormatConditionOperator) - A value or expression associated with the second part of the conditional format when the Operator argument is acBetween or acNotBetween (otherwise, this argument is ignored). Can be a constant or a string value.


Possible values are

acBetween The value must be between the values specified by the Expression1 and Expression2 arguments.
acEqual The value must equal to the value specified by the Expression1 argument.
acGreaterThan The value must be greater than the value specified by the Expression1 argument.
acGreaterThanOrEqual The value must be greater than or equal to the value specified by the Expression1 argument.
acLessThan The value must be less than the value specified by the Expression1 argument.
acLessThanOrEqual The value must be less than or equal to the value specified by the Expression1 argument.
acNotBetween The value must not be between the values specified by the Expression1 and Expression2 arguments.
acNotEqual The value must not be equal to the value specified by the Expression1 argument.

Count

You can use the Count property to determine the number of items in a specified collection.


CreateForm.Controls(1).FormatConditions.Count

Delete

Deletes the specified object.

You can use the Delete method of the FormatConditions collection to delete an existing FormatConditions collection from a combo box or text box control.


CreateForm.Controls(1).FormatConditions.Delete

Item

The Item property returns a specific member of a collection either by position or by index.

If the value provided for the Index argument doesn't match any existing member of the collection, an error occurs. The Item property is the default member of a collection, so you don't have to specify it explicitly. For example, the following two lines of code are equivalent.

Item (Index)

Index: An expression that specifies the position of a member of the collection referred to by the expression argument. If a numeric expression, the Index argument must be a number from 0 to the value of the collection's Count property minus 1. If a string expression, the Index argument must be the name of a member of the collection.


Debug.Print Modules(0)