Handling no results for docmd.applyfilter

断了今生、忘了曾经 提交于 2019-12-13 14:19:07

问题


I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the records in other controls (Text and Combo Boxes).

To achieve this, I am using the DoCmd.ApplyFilter method and I wanted to know if there is a way that I can handle the 'no results' scenario? What it does currently is shows all the display controls as empty, and the ID field says (AutoNumber) as if I was adding a new record.

If it is not possible to handle no results with DoCmd.ApplyFilter, then is there another way to search the records and handle the 'no results' scenario as well?


回答1:


You can check the recordsetclone to see if there are any records and remove the filter if there are not.

DoCmd.ApplyFilter , "id=5"
If Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "No records"
End If


来源:https://stackoverflow.com/questions/1730293/handling-no-results-for-docmd-applyfilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!