开发者

Access 2010 VBA: If no records match filter, display "No records found"

开发者 https://www.devze.com 2023-03-27 03:40 出处:网络
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'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 t开发者_如何学Chis would be most easily applied.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号