VB 多条件查询语句!~

2025-01-19 20:34:57
推荐回答(2个)
回答1:

我把完整的给你吧:

Private Sub Form_Load()
DTPicker2.Value = Date
Combo2.Text = Time
For i = 0 To 23
Combo1.AddItem i & ":00:00"
Combo2.AddItem i & ":00:00"
Next

Text1.Text = "请输入"
Text2.Text = "请输入"
Text3.Text = "请输入"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\luyin.mdb " & ";Persist Security Info=False"
Adodc1.RecordSource = "luyin"
Adodc1.Refresh
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\luyin.mdb " & ";Persist Security Info=False"
Adodc2.RecordSource = "luyin"
Adodc2.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Width = 800
DataGrid1.Columns(1).Width = 1200
DataGrid1.Columns(2).Width = 1200
DataGrid1.Columns(3).Width = 1200
DataGrid1.Columns(4).Width = 800
DataGrid1.Columns(5).Width = 1200
DataGrid1.Columns(6).Width = 1200
DataGrid1.Columns(7).Width = 1400
DataGrid1.Columns(8).Width = 0
End Sub

Private Sub Command1_Click()
Dim sqlStr As String, str0 As String, str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str7 As String, temp As String

str5 = " (录音日期 between #" & DTPicker1.Value & "# and #" & DTPicker2.Value & "#)"
str7 = "(录音起始时间>= " & "#" & Format(Combo1.Text, "hh:mm:ss") & "#" & " and 录音结束时间<= " & "#" & Format(Combo2.Text, "hh:mm:ss") & "#)"
str2 = IIf(Text1.Text = "请输入", "", "(来电号码='" & Text1.Text & "')")
str3 = IIf(Text2.Text = "请输入", "", "(去电号码='" & Text2.Text & "')")
str4 = IIf(Text3.Text = "请输入", "", "(通道说明='" & Text3.Text & "')")

str0 = "1=1"
str0 = str0 & IIf(Check5.Value = 1, " and " & str5, "") & IIf(Check7.Value = 1, " and " & str7, "") & IIf(Check2.Value = 1 And str2 <> "", " and " & str2, "") & IIf(Check3.Value = 1 And str3 <> "", " and " & str3, "") & IIf(Check4.Value = 1 And str4 <> "", " and " & str4, "")

str1 = "1=0"

For i = 0 To Check1.UBound
If Check1(i).Value = 1 Then
temp = Replace(Right(Check1(i).Caption, 2), "/", "")
str1 = str1 & " or 通道号='" & temp & "'"
End If
Next
str1 = IIf(str1 <> "1=0", " and (" & str1 & ")", "")

sqlStr = "select * from luyin where " & str0 & str1

Adodc1.RecordSource = sqlStr
Adodc1.Refresh

Set DataGrid1.DataSource = Adodc1
DataGrid1.Columns(0).Width = 800
DataGrid1.Columns(1).Width = 1200
DataGrid1.Columns(2).Width = 1200
DataGrid1.Columns(3).Width = 1200
DataGrid1.Columns(4).Width = 800
DataGrid1.Columns(5).Width = 1200
DataGrid1.Columns(6).Width = 1200
DataGrid1.Columns(7).Width = 1400
DataGrid1.Columns(8).Width = 0
End Sub

回答2:

select case 变量
case
case
end select