# MTFilter

The MTFilter object is used to build a filter string for either an ADO recordset or for use in generating a SQL query. By default, a filter criteria are considered together using AND logic. To create a filter string with an OR clause, use the CreateMergedFilter method.

To view an object model diagram that includes MTFilter, click here.

## ProgramID

MTSQLRowset.MTDataFilter.1

## Methods

Count | Returns the number of items in the collection.
Add | Adds filter criteria in the form of the column name, operator, and comparison value.
Remove | Removes a filter item at a specific index.
Clear | Clears the filter.
CreateMergedFilter | Creates a merged filter from the existing filter and the input filter. The merge action specifies whether the filter criteria should be joined with an AND or an OR.
Item | Gets the MTDataFilter interface pointer based on the index.
FilterString | Gets the combined filter string for use in an ADO filter or a SQL string.

## Properties

None.

# Method Detail

## Count

This method returns the number of items in the collection.

### Visual Basic Syntax

Count() As Long

C++ Syntax

HRESULT Count([out, retval] long *pVal);

## Add

This method adds filter criteria in the form of the column name, operator, and comparison value.

### Visual Basic Syntax

Add(Name As String, Operator As Variant, Value As Variant)

C++ Syntax

HRESULT Add([in] BSTR propName,[in] VARIANT aOperator,[in] VARIANT Value);

## Remove

This method removes a filter item at with a specific index.

### Visual Basic Syntax

Remove(Index As Long)

C++ Syntax

HRESULT Remove([in] long aIndex);

## Clear

This method clears the filter.

### Visual Basic Syntax

Clear()

C++ Syntax

HRESULT Clear();

## CreateMergedFilter

This method creates a merged filter from the existing filter and the input filter. The merge action specifies whether the filter criteria should be joined with an AND or an OR.

### Visual Basic Syntax

CreateMergedFilter(Filter As MTDataFilter, MergeAction As MTMergeAction) As MTDataFilter.

C++ Syntax

HRESULT CreateMergedFilter([in] IMTDataFilter* pFilter,[in] MTMergeAction aMergeAction,[out,retval] IMTDataFilter** pMergedFilter);

## Item

This method gets the MTDataFilter interface pointer based on the index.

### Visual Basic Syntax

Item(Index As Long) As MTFilterItem

C++ Syntax

HRESULT Item([in] long aIndex,[out, retval] IMTFilterItem* *pVal);

## FilterString

This method gets the combined filter string for use in an ADO filter or a SQL string.

### Visual Basic Syntax

FilterString(FilterStr As String)

C++ Syntax

HRESULT FilterString([in] BSTR pFilterStr);