Private Sub Command3_Click()
On Error GoTo askerr2
If Combo3.ListIndex < 0 Then
MsgBox "请先设置查询条件,选择要查询的字段", vbOKOnly, "提示"
ElseIf Combo4.ListIndex < 0 Then
MsgBox "请先设置查询条件,选择操作符", vbOKOnly, "提示"
ElseIf Text2.text = "" Then
MsgBox "请先输入要查询的值", vbOKOnly, "提示"
Else
If Combo4.text = "模糊查询" Then
strfilter2 = "select * from 用户数据表 where Combo3.list(Combo3.ListIndex) like %" & Trim(Text2.text) & "%"
ElseIf Combo4.text = "精确查询" Then
strfilter2 = "select * from 用户数据表 where " & Combo3.list(Combo3.ListIndex) & " " & "=" & " " & "" & Trim(Text2.text) & ""
End If
Adodc2.RecordSource = strfilter2
Adodc2.Refresh
If Err.Number <> 0 Then
msg = "查询条件出错,查询的值与字段类型不匹配,请重新设置查询条件!"
MsgBox msg, , "出错", Err.HelpFile, Err.HelpContext
Else
MsgBox "总共查询到" + CStr(Adodc2.Recordset.RecordCount) + "条记录,详细内容见上表", vbOKOnly, "查询结果提示"
End If
End If
Exit Sub
askerr2:
MsgBox "查询条件出错,查询的值与字段类型不匹配,请重新设置查询条件!"
End Sub
模糊查询总是直接跳到askerr2了,但是精确查询没有任何问题,曾经把精确查询的=改成like,用作模糊查询,还是不行
哪位英雄帮小弟我解决一下
strfilter2 = "select * from 用户数据表 where " & Combo3.list(Combo3.ListIndex) & "like %" & Trim(Text2.text) & "%"
你把你的strfilter2变量debug.print出来,放到查询分析器看看是什么错误!
strfilter2 = "select * from 用户数据表 where " & Combo3.list(Combo3.ListIndex) & " like %" & Trim(Text2.text) & "%"
注意空格!!
同上
去掉
On Error GoTo askerr2
看看你的错误
你可能还不是
很了解‘’ “” 的含义
strfilter2 = "select * from 用户数据表 where " & Combo3.list(Combo3.ListIndex) & " like %" & Trim(Text2.text) & "%"
楼上的少了一个空格