Search code examples
vb6adodbrecordset

ADO Recordset filter comparing two fields


How can I filter a recordset by comparing two fields?

For a given ADO Recordset with n fields (Field1, Field2,...,Fieldn)

I used to filter a field against a value:

rs.Filter = "Field1 = 'something'"

But what I need to do is something like this:

rs.Filter = "Field1 = Field2"

Is that possible?


Solution

  • The criteria string is made up of clauses in the form FieldName-Operator-Value

    Value is the value with which you will compare the field values (for example, 'Smith', #8/24/95#, 12.345, or $50.00). Use single quotes with strings and pound signs (#) with dates. For numbers, you can use decimal points, dollar signs, and scientific notation. If Operator is LIKE, Value can use wildcards. Only the asterisk (*) and percent sign (%) wild cards are allowed, and they must be the last character in the string. Value cannot be null.

    This suggests that comparing fields to each other is not supported. Value must be a literal.