如何获取指示 Recordset.Find 是否找到任何内容的值?

发布于 2024-07-16 05:02:57 字数 758 浏览 11 评论 0原文

我编写了一个程序,可以添加、删除、保存和搜索数据库(记录集)中的记录。 然而我是在一个团队中做的。 我的任务是将搜索功能添加到我已有的程序中; 但是,当有人键入数据库/记录集中不存在的单词/任何内容时,我在添加错误消息时遇到问题。

因此,例如在文本框(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-07-23 05:02:57

以下是如何执行您想要执行的操作的示例: 方法:记录集::Find

代码示例:

adoCustomer.Recordset.MoveFirst
adoCustomer.Recordset.Find "LastName='" & txtFindBox.Text & "'"
If (adoCustomer.Recordset.BOF = True) OR (adoCustomer.Recordset.EOF = True) Then
   MsgBox "Record not found"
End If

您需要检查 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:

adoCustomer.Recordset.MoveFirst
adoCustomer.Recordset.Find "LastName='" & txtFindBox.Text & "'"
If (adoCustomer.Recordset.BOF = True) OR (adoCustomer.Recordset.EOF = True) Then
   MsgBox "Record not found"
End If

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文