我在Access 2016中有一个表Table1
(主键= Code
),其中包含以下值:
=====+=============
Code + Name
=====+=============
A1 | AU All
A2 | AU Large
A3 | AU Size
A4 | Unassigned
=====+=============
我有一个查询,Query1
定义为:
SELECT Table1.Code
FROM Table1
WHERE (((Table1.Name) Not Like "AU *"));
在Access中,查询返回1条记录,如预期的那样:
Code
======
A4
======
但是,当我使用ADO 2.8或6.1打开查询时,使用以下代码:
Option Compare Database
Option Explicit
Sub test()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
With rst
.Open "Query1", CurrentProject.Connection, adOpenStatic, adLockReadOnly
Do While Not .EOF
Debug.Print .Fields("Code").Value
.MoveNext
Loop
Debug.Print "Record Count : " & .RecordCount
.Close
End With
End Sub
返回所有4条记录,如调试输出所示:
A1
A2
A3
A4
Record Count : 4
为什么我会得到不同的结果?
答案 0 :(得分:4)
尝试从*到%的外卡字符
.Open "SELECT Table1.Code FROM Table1
WHERE (((Table1.Name) Not Like 'AU %'))",
CurrentProject.Connection, adOpenStatic, adLockReadOnly
查看更多details