Access 2010 VBA:如果没有记录匹配过滤器,则显示“未找到记录”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7027671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access 2010 VBA: If no records match filter, display "No records found"
提问by music2myear
I'd like a query to return text such as "No records found matching criteria." or the like when there are no records that meet the entered criteria.
我想要一个查询来返回文本,例如“没有找到匹配条件的记录”。当没有符合输入条件的记录时,或类似情况。
I'm using Access 2010 and can use VBA or SQL. I'd imagine the query (SQL) is where this would be most easily applied.
我使用的是 Access 2010,可以使用 VBA 或 SQL。我想查询 (SQL) 是最容易应用的地方。
回答by chip
My first thought would be to do something like this::
我的第一个想法是做这样的事情::
sql = "SELECT * FROM table WHERE SomeID = 123"
Set rst = CurrentDb.OpenRecordset(sql)
If rst.recordcount = 0 Then
Debug.print "Nothing to see, move along"
Else
' Do something useful
End If
If you are using a query built in the QBE you can do something similar and open the recordset using the stored querydef instead of a sql string.
如果您使用 QBE 中内置的查询,您可以执行类似的操作并使用存储的 querydef 而不是 sql 字符串打开记录集。