如何获取指示 Recordset.Find 是否找到任何内容的值?
我编写了一个程序,可以添加、删除、保存和搜索数据库(记录集)中的记录。 然而我是在一个团队中做的。 我的任务是将搜索功能添加到我已有的程序中; 但是,当有人键入数据库/记录集中不存在的单词/任何内容时,我在添加错误消息时遇到问题。
因此,例如在文本框(txtFindBox.Text)中,如果输入“ashbndash”,则会出现错误消息。 我已经注释掉了我自己的错误消息框,但请告诉我哪里出错了:(
这是查找按钮的代码。
Private Sub cmdFindDB_Click()
adoCustomer.Recordset.MoveFirst
If optLastName.Value = True Then
adoCustomer.Recordset.Find "LastName='" & txtFindBox.Text & "'"
'Else
'MsgBox ("NO RECORD FOUND")
End If
If OptFirstName.Value = True Then
adoCustomer.Recordset.Find "FirstName='" & txtFindBox.Text & "'"
'Else
'MsgBox ("NO RECORD FOUND")
End If
End Sub
编辑:就像说问题是每次我点击“查找”按钮时即使它找到了答案,也会在 msgbox 中出现消息“NO RECORD FOUND”,如果您也输入乱码,它也会出现该消息。
感谢您的时间
问候 Haroon。
I wrote a program that would add, delete, save and search through records in a database (recordset). However I was doing it in a team. My task was to add the search function to the program, which I have; however I am having problems with adding an error message for when somebody types a word/anything that isn't in the database/recordset.
So for example in the textbox(txtFindBox.Text) if they type "ashbndash" it would come up with an error message. I've commented out my own error message boxes but tell me where I'm going wrong please :(
Here's the code for the find button.
Private Sub cmdFindDB_Click()
adoCustomer.Recordset.MoveFirst
If optLastName.Value = True Then
adoCustomer.Recordset.Find "LastName='" & txtFindBox.Text & "'"
'Else
'MsgBox ("NO RECORD FOUND")
End If
If OptFirstName.Value = True Then
adoCustomer.Recordset.Find "FirstName='" & txtFindBox.Text & "'"
'Else
'MsgBox ("NO RECORD FOUND")
End If
End Sub
edit: Just like to say the problem is that every time I hit the button 'find' it comes up with the message "NO RECORD FOUND" in a msgbox even though it finds the answer, it also comes up with that msgbox if you type in gibberish too.
Thanks for your time
Regards Haroon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是如何执行您想要执行的操作的示例: 方法:记录集::Find
代码示例:
您需要检查 EOF 和 BOF,而不是检查 Value 属性是否为 true。 它们代表文件结束和文件开始。 因此,如果任一情况为真,则您不在记录集“内部”,这意味着您没有找到任何内容。
Here is an example of how to do what you are trying to do: METHOD: Recordset::Find
Example for your code:
Instead of checking that the Value property is true, you need to check EOF and BOF. These stand for End Of File and Beginning Of File. So if either is true, then you are not "inside" the recordset, meaning you did not find anything.