使用 DAO 选择具有最高时间戳的给定 ID 的记录

Select the record of a given id with the highest timestamp using DAO

本文关键字:ID 记录 时间戳 选择 DAO 使用      更新时间:2023-10-16

如何在记录集上使用DAO执行以下操作

SELECT TOP 1 * FROM foo WHERE id = 10 ORDER BY timestamp DESC
使用

SetCurrentIndex,您只能使用一个索引,否则使用 id时间戳,选择第一个就可以了。

我不确定你想要什么。

Dim rs As DAO.Recordset
Dim db As Database
Set db = CurrentDB
sSQL = "SELECT TOP 1 * FROM foo WHERE id = 10 ORDER BY timestamp DESC"
Set rs = db.OpenRecordset(sSQL)

查找不适用于所有记录集。这将起作用:

Set rs = CurrentDb.OpenRecordset("select * from table1")
rs.FindFirst "akey=1 and atext='b'"
If Not rs.EOF Then Debug.Print rs!AKey

这不会:

Set rs = CurrentDb.OpenRecordset("table1")
rs.FindFirst "akey=1 and atext='b'"