Microsoft KB Archive/280811

= PRB: Mixing &quot;And&quot; and &quot;Or&quot; Criteria in the Same Filter Returns a 3001 Error Message =

Article ID: 280811

Article Last Modified on 8/23/2001

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q280811



SYMPTOMS
Mixing And and Or criteria in the same filter returns the following error message:

Runtime Error '3001' Arguments are of the wrong type, are out of acceptable range or are in conflict with one another.



CAUSE
Although there is no precedence when evaluating criteria, when you use And and Or together in the Filter property, the or criteria must be the last comparison made.



RESOLUTION
To resolve the error message, use criteria that allows the Or to be the top comparison.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Start a new Microsoft Visual Basic Standard EXE project. Form1 is created by default. On the Project menu, click References, and then add a Reference to the Microsoft ActiveX Data Objects 2.X Library.  Insert the following code into the General Declaration section of Form1: Option Explicit Dim cn As ADODB.Connection Dim rs As ADODB.Recordset

Private Sub Form_Load Set cn = New ADODB.Connection Set rs = New ADODB.Recordset

cn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Password=;Data Source=path to nwind2000.mdb;User ID=Admin;Password=;&quot; rs.Open &quot;Select * from employees&quot;, cn, adOpenDynamic, adLockOptimistic rs.Filter = &quot;((lastname like 'd%')OR (lastname like 'l%')) AND (title='sales representative')&quot; 'rs.Filter = &quot;(lastname like 'd%' AND title = 'sales representative') OR (lastname like 'l%' AND title = 'sales representative')&quot;

rs.MoveFirst Do While Not rs.EOF Debug.Print rs.Fields(0).Value rs.MoveNext Loop End Sub  Press the F5 key to run the project, and note that error message 3001 is returned. Uncomment the second rs.filter line and comment the first. This time, when the project is run, note that three records are returned to the Immediate window.</li></ol>

Keywords: kbdatabase kbprb KB280811

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.