举例说明,实现如下多条件查询:
Private Sub Command1_Click() Dim jsql jsql = ""
Dim smyregion As String If Check1.Value = 1 Then
jsql = "图书名称 like '%" + Text1.Text + "%'" End If
If Check2.Value = 1 Then If jsql = "" Then
jsql = "作者姓名 like'%" + Text2.Text + "%'" Else
jsql = jsql & "and 作者姓名 like'%" + Text2.Text + "%'" End If End If
If Check3.Value = 1 Then If jsql = "" Then
jsql = "出版社名称 like'%" + Text3.Text + "%'" Else
jsql = jsql & "and 出版社名称 like '%" + Text3.Text + "%'" End If End If
If Check4.Value = 1 Then If jsql = "" Then
jsql = "出版时间 like '%" + Text4.Text + "%'" Else
jsql = jsql & "and 出版时间 like '%" + Text3.Text + "%'" End If End If
If Check5.Value = 1 Then If jsql = "" Then
jsql = "图书类别 like '%" + Text5.Text + "%'"
Else
jsql = jsql & "and 图书类别 like '%" + Text5.Text + "%'" End If End If
If jsql = "" Then
MsgBox "请选择查询条件!", vbInformation, "图书音像管理系统" Exit Sub Else
Adodc1.RecordSource = "select * from book where " & jsql Adodc1.Refresh End If
If Adodc1.Recordset.RecordCount > 0 Then Set DataGrid1.DataSource = Adodc1 End If End Sub
Private Sub Command2_Click() Unload Me End Sub