PRB: Error 3001 Comparing Fields as Criteria to Filter Recordset (216873)
The information in this article applies to:
- ActiveX Data Objects (ADO) 2.0
- ActiveX Data Objects (ADO) 2.01
- ActiveX Data Objects (ADO) 2.1
- ActiveX Data Objects (ADO) 2.1 SP2
- ActiveX Data Objects (ADO) 2.5
- ActiveX Data Objects (ADO) 2.6
- ActiveX Data Objects (ADO) 2.7
This article was previously published under Q216873 SYMPTOMS
Comparing two fields in the criteria string of the ADO Filter property (for example: The criteria string is made up of clauses in the form: " FieldName Operator FieldName ") generates the following error:
Runtime error '3001':
The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.
CAUSE
This functionality cannot be accomplished with current versions of ADO. The criteria syntax of the ADO Filter property is defined as follows:
" FieldName Operator 'Literal_Value' "
The 'Literal_Value' data type could be string, number, or date. You cannot use the preceding expression to compare two fields. Attempting to do so raises error 3001.
RESOLUTION
One workaround is to have several expressions joined by Boolean operators as the Filter criteria. You can only use this if the the values of compared fields are known to the developer. This way the developer can come up with a formula for the criteria string that meets the required results. For example:
rs.Filter = "Field1 Operator1 'Value1' AND Field2 Operator2 'Value2'"
If the developer does not know the values for Field1 and Field2, then the developer has to use either a custom Filter routine (within the client application) or a stored procedure (on the server side) to accomplish the functionality dynamically. You can use control-flow statements within the custom Filter routine (or the stored procedure) to perform the necessary Field comparisons and generate the expected results.
This article provides a demonstration for such a routine in the "MORE INFORMATION" section of this article.
WARNING: The workaround, provided in the MORE INFORMATION section, is only given for illustration purpose, without any warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. REFERENCES
For more information, please refer to the ADO Help documentation.
For additional information, please see the following article in the Microsoft Knowledge Base: 195222 PRB: ADO Find Method Only Supports One Criteria
Modification Type: | Major | Last Reviewed: | 8/24/2001 |
---|
Keywords: | kbcode kbDatabase kbDSupport kbprb KB216873 |
---|
|