sql 查询 Text1.Text 输入非空的才拼条件 出现FORM子语法错误
Dim cn As New ADODB.ConnectionDim rs As New ADODB.Recordset
Dim sql As String
Dim sqlWhere As String
Private Sub Command1_Click() '查询
If cn.State = adStateOpen Then cn.Close
If rs.State = adStateOpen Then rs.Close
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/db.mdb;Persist Security Info=False"
sqlWhere = vbNullString
If Trim(Text1.Text) = "" Then
sqlWhere = sqlWhere & 年级 like '" & Combo1.Text & "' and 班级 like '" & Combo2.Text & "'"
End If
If Trim(Text1.Text) <> 0 Then
sqlWhere = sqlWhere & 年级 like '" & Combo1.Text & "' and 班级 like '" & Combo2.Text & "' and 姓名 like '" & Text1.Text & "'
End If
sql = "select * from 档案 " & sqlWhere
rs.Open sql, cn, 3, 3 出现FORM子语法错误