VBA无法执行代码

时间:2015-02-05 05:00:42

标签: excel vba excel-vba recordset

我的问题是,无论我在文本框中输入什么内容,它都只会执行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

1 个答案:

答案 0 :(得分:0)

尝试替换此行:

If Not rst.EOF Then

这一行

If rst.RecordCount <> 0 Then