为什么 ADO 记录集 return 的记录比基础 Access 查询多

Why does ADO recordset return more records than the underlying Access query

我在 Access 2016(主键 = Code)中有一个 table Table1,具有以下值:

=====+=============
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 中,查询 returns 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

为什么我得到不同的结果?

尝试从 * 到 % 的通配符

  .Open "SELECT Table1.Code FROM Table1 
WHERE (((Table1.Name) Not Like 'AU %'))", 
CurrentProject.Connection, adOpenStatic, adLockReadOnly

查看更多details