“未找到记录”的VBA代码正在搜索 [英] VBA code for "No records found" in search

查看:91
本文介绍了“未找到记录”的VBA代码正在搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮忙吗?我有这个代码,所以当我为我的组合框选择值链接到查找表中的值时,它会打开我的frmriskass。只有基于我在下面的代码中内置的查询的相应记录,该查询应用于我的搜索表单中的搜索命令按钮。


Private Sub Command4_Click()

DoCmd.OpenForm" frmriskass",acNormal," qrysearchriskass",acFormReadOnly

Me.Area =""

End Sub


当有匹配的记录时它工作正常,但我遇到的问题是没有相应的记录。我得到的只是一个空白表格,上面没有字段或命令按钮。


我如何更改代码,以便如果没有相应的记录,我会得到一个消息框,上面写着类似没有相应记录,请再次搜索的内容而不是打开一个空白表格我可以点击确定然后回到我原来的搜索表单再试一次?

Can anybody help? I have this code i have put together so that when i select values for my combo boxes which are linked to values in lookup tables, it opens my "frmriskass" with only the corresponding records based on a query i have built in to the code below which is applied to the search command button in my search form.

Private Sub Command4_Click()
DoCmd.OpenForm "frmriskass", acNormal, "qrysearchriskass", , acFormReadOnly
Me.Area = ""
End Sub

It works fine when there is a matching record, but the problem i have is when there is no corresponding record. All i get is a blank form whith no fields or command buttons on it.

How do i change the code so that if there are no corresponding records i will get a message box which says something like "No corresponding record, please search again" and instead of a blank form being opened i can click Ok and go back to my original search form to try again?

推荐答案

对不起。刚刚意识到我有代码作为acFormReadOnly但已将其更改为acFormEdit所以我仍然可以输入到找到的相应记录,但是如果没有相应的记录,我知道只是得到一个空表格准备完成。仍然需要代码,所以这不会发生。

Sorry. Just realised i had code as acFormReadOnly but have changed this to acFormEdit so i can still input in to the appropriate records found, however if there is no corresponding record i know just get an empty form ready to be completed. Still need code so this doesn''t happen.


有人可以提供帮助吗?我有这个代码,所以当我为我的组合框选择值链接到查找表中的值时,它会打开我的frmriskass。只有基于我在下面的代码中内置的查询的相应记录,该查询应用于我的搜索表单中的搜索命令按钮。


Private Sub Command4_Click()

DoCmd.OpenForm" frmriskass",acNormal," qrysearchriskass",acFormReadOnly

Me.Area =""

End Sub


当有匹配的记录时它工作正常,但我遇到的问题是没有相应的记录。我得到的只是一个空白表格,上面没有字段或命令按钮。


我如何更改代码,以便如果没有相应的记录,我会得到一个消息框,上面写着类似没有相应记录,请再次搜索的内容而不是打开一个空白表单我可以单击确定并返回到我原来的搜索表单再试一次?
Can anybody help? I have this code i have put together so that when i select values for my combo boxes which are linked to values in lookup tables, it opens my "frmriskass" with only the corresponding records based on a query i have built in to the code below which is applied to the search command button in my search form.

Private Sub Command4_Click()
DoCmd.OpenForm "frmriskass", acNormal, "qrysearchriskass", , acFormReadOnly
Me.Area = ""
End Sub

It works fine when there is a matching record, but the problem i have is when there is no corresponding record. All i get is a blank form whith no fields or command buttons on it.

How do i change the code so that if there are no corresponding records i will get a message box which says something like "No corresponding record, please search again" and instead of a blank form being opened i can click Ok and go back to my original search form to try again?


你可以发布过滤器的sql。
Can you post the sql for the filter.


我对这个过滤器的sql如下: br />

SELECT tblRiskAss.ReferenceNumber,tblRiskAss.RiskAssessorsName,tblRiskAss。[Hospice Premesis],tblRiskAss.Area,tblRiskAss.Date,tblRiskAss。[Hazard Group Name],tblRiskAss。[State Problem and Risk] ],tblRiskAss。[风险等级],tblRiskAss。[采取行动],tblRiskAss。[管理状态],tblRiskAss。[风险人物],tblRiskAss。[风险通信],tblRiskAss。[评估审核期],tblRiskAss。[ [监控频率],tblRiskAss.AssessmentReviewDate,tblRiskAss。[Last review],tblRiskAss.NextReviewDate,tblRiskAss.Completed,tblRiskAss.ysnSentByMailToStaff

FROM tblRiskAss

WHERE(((tblRiskAss .RiskAssessorsName)= [Forms]![frmsearchriskass]![RiskAssessorsName])AND((tblRiskAss.Area)= [Forms]![frmsearchriskass]![Area]));


它过滤匹配[风险评估员名称]和[区域]。


只是不确定为什么如果没有与此过滤器相匹配的话仍然会显示一个准备好输入数据的空白表格,或者如果有匹配则会得到匹配的记录加上一个空白的表格来完成如果你用鼠标滚轮滚动。


希望你能提供帮助。


谢谢
The sql i have for this filter is below:

SELECT tblRiskAss.ReferenceNumber, tblRiskAss.RiskAssessorsName, tblRiskAss.[Hospice Premesis], tblRiskAss.Area, tblRiskAss.Date, tblRiskAss.[Hazard Group Name], tblRiskAss.[State Problem and Risk], tblRiskAss.[Risk Level], tblRiskAss.[Action Taken], tblRiskAss.[Management Status], tblRiskAss.[Person at Risk], tblRiskAss.[Risk Communicated To], tblRiskAss.[Assessment Review Period], tblRiskAss.[Frequency of Monitoring], tblRiskAss.AssessmentReviewDate, tblRiskAss.[Last Reviewed], tblRiskAss.NextReviewDate, tblRiskAss.Completed, tblRiskAss.ysnSentByMailToStaff
FROM tblRiskAss
WHERE (((tblRiskAss.RiskAssessorsName)=[Forms]![frmsearchriskass]![RiskAssessorsName]) AND ((tblRiskAss.Area)=[Forms]![frmsearchriskass]![Area]));

It filters for matching [Risk Assessors Name] and [Area].

Just not sure why it still brings up a blank form ready for data input if no matches for this filter or if there are matches you get the matching record plus a blank one to complete if you scroll with the mouse wheel.

Hope you can help.

Thanks


这篇关于“未找到记录”的VBA代码正在搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆