这个窗体整理的时间比较长,理清逻辑有点难,上图了~~
Private Sub cmdok_Click()
Dim txtsql As String
Dim msgtext As String
Dim mrc As ADODB.Recordset
'初始查询
txtsql = "select * from online_Info where "
Set mrc = ExecuteSQL(txtsql, msgtext)
If Trim(comFieldname1.Text) = "" Or Trim(comOperator1.Text) = "" Or Trim(txtQuerycontent1.Text) = "" Then
MsgBox "请将第一行内容补充完整!", 48, "警告"
Else
'组合查询
txtsql = txtsql & Trim(field(comFieldname1.Text)) & " " & Trim(comOperator1.Text) & "'" & Trim(txtQuerycontent1.Text) & "'"
If Trim(comSyntheticrelation1.Text) <> "" Then '如果组合关系1为空
'如果第二行判断条件为空
If Trim(comFieldname2.Text) = "" Or Trim(comOperator2.Text) = "" Or Trim(txtQuerycontent2.Text) = "" Then
MsgBox "请将第二行内容补充完整!", 48, "警告" '提示
Else '如果不为空
txtsql = txtsql & " " & RelationName(comSyntheticrelation1.Text) & " " & field(comFieldname2.Text) & " " & comOperator2.Text & "'" & Format(Trim(txtQuerycontent2.Text)) & "'"
If Trim(comSyntheticrelation2.Text) <> "" Then '如果组合关系2为空
'如果第三行判断条件为空
If Trim(comFieldname3.Text) = "" Or Trim(comOperator3.Text) = "" Or Trim(txtQuerycontent3.Text) = "" Then
MsgBox "请将第三行内容补充完整!", 48, "警告"
Exit Sub
Else
txtsql = txtsql & " " & RelationName(comSyntheticrelation2.Text) & " " & field(comFieldname3.Text) & "" & comOperator3.Text & "'" & Trim(txtQuerycontent3.Text) & "'"
End If
End If
End If
End If
End If
Set mrc = ExecuteSQL(txtsql, msgtext)
If mrc.EOF Then
MsgBox "没有您要查找的学生上机记录!", vbOKOnly + vbCritical, "查询提示"
comFieldname1.SetFocus
MsShow.Rows = 1
Else
MsShow.Clear
With MsShow '添加表头
.Rows = 1 '紧贴第一行
.CellAlignment = 4
.TextMatrix(0, 0) = "卡号"
.TextMatrix(0, 1) = "姓名"
.TextMatrix(0, 2) = "上机日期"
.TextMatrix(0, 3) = "上机时间"
.TextMatrix(0, 4) = "余额"
If mrc.BOF Then '判断数据库是否为空
MsgBox "学生上机记录为空!"
Exit Sub
End If
With MsShow
Do While mrc.EOF = False '逐行添加数据
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0))
.TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(3))
.TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(6))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(7))
.TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(8))
mrc.MoveNext
Loop
End With
End With
End If
End Sub