【发布时间】:2015-02-05 13:26:32
【问题描述】:
我的问题是,无论我在文本框中输入什么,即使数据库中不存在该记录,它也只会执行MsgBox ("Estimate No" & editform.edittext.Value & " is found")。它应该执行代码
MsgBox ("Unable to find '" & editform.edittext.Value & "'") 在数据库中找不到记录时。
If editform.OptionButton1.Value = True Then
strConnectStr = "something"
Qry = "SELECT * " & _
"FROM test.dbo.estimateRegister " & _
"WHERE test.dbo.estimateRegister.estimateNo = '" & edittext.Text & "%'"
cnt.Open strConnectStr
rst.Open Qry, cnt
If Not rst.EOF Then
MsgBox ("Estimate No" & editform.edittext.Value & " is found")
Unload Me
UserForm2.Show
Else
MsgBox ("Unable to find '" & editform.edittext.Value & "'")
End If
End If
【问题讨论】:
-
尝试删除大括号...只是 MsgBox "Message"
-
没有区别。我试过了。
-
您在代码中
If Not rst.EOF Then ...之前的某个位置是否有On Error Resume Next?如果是这样,那么rst可能是Nothing或另一个此时没有.EOF的对象。 -
不。我没有任何代码
-
那么此时
rst是一个什么样的对象呢?您是否尝试过单步调试并在本地窗口中查看rst?或者将rst.RecordCount分配给一个变量并观察这个变量?也许有记录集?