版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
当自己没思路的时候 不妨多查查博客。 会有极大的收获。
首先你要判断第一组和是否为空,然后选择组合关系后判断二、三组合是否空值。
下面是代码
txtsql = "select * from worklog_info where "
If Trim(Combo1.Text) = "" Or Trim(Combo4.Text) = "" Or Trim(Text1.Text) = "" Then
MsgBox "请将第一行选项内容填写完整!", , "提示"
Exit Sub
Else
txtsql = txtsql & " " & field(Combo1.Text) & " " & Combo4.Text & " '" & Trim(Text1.Text) & "'"
If Combo7.Text <> "" Then
If Combo2.Text = "" Or Combo5.Text = "" Or Text2.Text = "" Then
MsgBox "请将第二行选项内容填写完整!", , "提示"
Exit Sub
Else
txtsql = txtsql & " " & RelationName(Combo7.Text) & " " & field(Combo2.Text) & Combo5.Text & "'" & Trim(Text2.Text) & "'"
If Combo8.Text <> "" Then
If Combo3.Text = "" Or Combo6.Text = "" Or Text3.Text = "" Then
MsgBox "请将第三行选项内容填写完整!", , "提示"
Exit Sub
Else
txtsql = txtsql & " " & RelationName(Combo8.Text) & " " & field(Combo3.Text) & "" & Combo6.Text & "'" & Trim(Text3.Text) & "'"
End If
End If
End If
End If
Set mrc = ExecuteSQL(txtsql, Msgtext)
If mrc.EOF Then
MsgBox "没有数据,请重新填写!", , "提示"
Text1.SetFocus
MSFlexGrid1.Clear
MSFlexGrid1.Rows = 2
Exit Sub
Else
With MSFlexGrid1
.Rows = 1
.TextMatrix(0, 0) = "序列号"
.TextMatrix(0, 1) = "教师"
.TextMatrix(0, 2) = "级别"
.TextMatrix(0, 3) = "注册日期"
.TextMatrix(0, 4) = "注册时间"
.TextMatrix(0, 5) = "注销日期"
.TextMatrix(0, 6) = "注销时间"
.TextMatrix(0, 7) = "机器名"
.TextMatrix(0, 8) = "状态"
Do While Not mrc.EOF
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0))
.TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(1))
.TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(2))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(3))
.TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(4))
.TextMatrix(.Rows - 1, 5) = Trim(mrc.Fields(5)) & ""
.TextMatrix(.Rows - 1, 6) = Trim(mrc.Fields(6)) & ""
.TextMatrix(.Rows - 1, 7) = Trim(mrc.Fields(7))
.TextMatrix(.Rows - 1, 8) = Trim(mrc.Fields(8))
mrc.MoveNext
Loop
End With
End If
End If
这是防止输出不正确格式,带来不必要麻烦
Private Sub Combo1_Click()
If Combo1.Text = "注销日期" Or Combo1.Text = "注册日期" Then
MonthView1.Visible = True
End If
If Combo1.Text = "教师" Or Combo1.Text = "机器号" Or Combo1.Text = "注册时间" Or Combo1.Text = "注销时间" Then
Text1.Text = ""
MonthView1.Visible = False
End If
If Combo1.Text = "注销时间" Or Combo1.Text = "注册时间" Then
MsgBox " 查询内容格式为00:00:00"
End If
End Sub
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Text1.Text = MonthView1.Year & "-" & MonthView1.Month & "-" & MonthView1.Day
MonthView1.Visible = False
End Sub