Access 2010 VBA: If no records match filter, display "No records found"
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.
精彩评论