Private Sub Command1_Click()
Dim rst As New ADODB.Recordset
Dim i As Integer
rst.CursorLocation = adUseClient
'构建记录集结构
With rst.Fields
.Append "x", adChar, 1
.Append "y", adChar, 1
End With
rst.Open
'初始化数据
For i = 0 To 5
rst.AddNew
rst("x") = "5"
rst("y") = CStr(i + 2)
rst.Update
Next
'单纯用OR
rst.Filter = "x='5' or y='3'"
MsgBox rst.RecordCount
'单纯用AND
rst.Filter = "x='5' and y='3'"
MsgBox rst.RecordCount
'传统的思维方法,在这里是不能正确运行的
'rst.Filter = "x='5' and (y='3' or y='4')"
'MsgBox rst.RecordCount
'把代码拆开,就可以了
rst.Filter = "(x='5' and y='3') or (x='5' and y='4')"
MsgBox rst.RecordCount
End Sub