变量名 | 含义 |
---|---|
c(2) | 判断条件框中是否为空 |
CField | 字段名函数变量 |
CSymbol | 操作符函数变量 |
CContent | 组合关系变量 |
代码部分:
Private Sub cmdInquiry_Click()
Dim c(2) As Boolean '判断条件中的格子中是否有数据
'查询内容变量的实例化
Set ctt = frmInquiryLineSumInfo
'如果时间框显示,将时间框的值赋给txtContent框
If DTPicker1.Visible = True Then
txtContent1.Text = DTPicker1.Value
End If
'如果时间框显示,将时间框的值赋给txtContent框
If DTPicker2.Visible = True Then
txtContent2.Text = DTPicker2.Value
End If
'如果时间框显示,将时间框的值赋给txtContent框
If DTPicker3.Visible = True Then
txtContent3.Text = DTPicker3.Value
End If
'判断三个条件对应的框中是否为空
If cobField1.Text = "" Or cobSymbol1.Text = "" Or txtContent1.Text = "" Then
Else
c(0) = True
If cobField2.Text = "" Or cobSymbol2.Text = "" Or txtContent2.Text = "" Then
Else
c(1) = True
If cobField3.Text = "" Or cobSymbol3.Text = "" Or txtContent3.Text = "" Then
Else
c(2) = True
End If
End If
End If
txtSQL = "select * from line_Info where "
'组合查询所有的情况
'第一行数据查询
If cobRelation1.Text = "" And cobRelation2.Text = "" Then
If c(0) Then
'0
txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Call add
mrc.Close
Else
MsgBox "请输入必要条件"
End If
End If
'两行数据查询
If cobRelation1.Text <> "" And cobRelation2.Text = "" Then
If c(1) Then
If cobRelation1.Text = "或" Then
'0 or 1
txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "or " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Call add
mrc.Close
Else
If cobRelation1.Text = "与" Then
'0 and 1
txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "and " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Call add
mrc.Close
Else
MsgBox "请选择组合关系"
End If
End If
Else
MsgBox "请输入必要条件"
End If
End If
'3行数据查询
If cobRelation1.Text <> "" And cobRelation2.Text <> "" Then
If c(2) Then
If cobRelation2.Text = "或" Then
'0 or 1 or 2
txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "or " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'" & "or " & CField(cobField3.Text) & CSymbol(cobSymbol3.Text) & " '" & CContent(txtContent3.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Call add
mrc.Close
Else
If cobRelation2.Text = "与" Then
'0 and 1 and 2
txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "and " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'" & "and " & CField(cobField3.Text) & CSymbol(cobSymbol3.Text) & " '" & CContent(txtContent3.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Call add
mrc.Close
Exit Sub
Else
MsgBox "请输入第二个组合条件"
End If
End If
Else
MsgBox "请输入必要条件"
End If
End If
'避免发生逻辑错误
If cobRelation1.Text = "" And cobRelation2.Text <> "" Then
MsgBox "请输入必要条件"
End If
End Sub