一、思维导图(以操作员工记录为例)
二、思路
(1)往窗体里面添加数据 这里最好定义数组
如:`在这里插Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim n As Integer
'打开窗体时的加载内容
For i = 0 To 2
comboField(i).AddItem "教师"
comboField(i).AddItem "注册日期"
comboField(i).AddItem "注册时间"
comboField(i).AddItem "注销日期"
comboField(i).AddItem "注册时间"
comboField(i).AddItem "机器名"
Next
For j = 0 To 2
comboOpSign(j).AddItem ">"
comboOpSign(j).AddItem "<"
comboOpSign(j).AddItem "="
comboOpSign(j).AddItem "<>"
Next j
For n = 0 To 1
comboCombineRelation(n).AddItem "与"
comboCombineRelation(n).AddItem "或"
Next n
End Sub入代码片`
(2)进行查询语句
在做这方面的时候,一定要理清楚思路再做,为了写代码,错了又错,改了又改。
Private Sub cmdInquiry_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
txtSQL = "select * from worklog_Info where level='管理员' or level= '一般用户'"
' txtSQL = "select * from worklog_Info where level='" & Trim(一般用户) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "请输入操作员账号!", vbOKOnly + vbExclamation, "警告"
Else
txtSQL = "select * from worklog_Info where"
If Trim(comboField(0).Text) = "" Or Trim(comboOpSign(0).Text) = "" Or Trim(txtInquiryContent(0).Text) = "" Then
MsgBox "请将第一行选项内容填写完整!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
txtSQL = txtSQL & " " & FiledName(comboField(0).Text) & " " & Trim(comboOpSign(0).Text) & "'" & Trim(txtInquiryContent(0).Text) & "'"
If Trim(comboCombineRelation(0).Text) <> "" Then
If Trim(comboField(1).Text) = "" Or Trim(comboOpSign(1).Text) = "" Or Trim(txtInquiryContent2.Text) = "" Then
MsgBox "请将第二行选项内容填写完整!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Else
txtSQL = txtSQL & " " & Relationname(comboCombineRelation(0).Text) & " " & FiledName(comboField(1).Text) & " " & Trim(comboOpSign(1).Text) & "'" & Trim(txtInquiryContent(1).Text) & "'"
End If
End If
If Trim(comboCombineRelation(1).Text) <> "" Then
If Trim(comboField(2).Text) = "" Or Trim(comboOpSign(2).Text) = "" Or Trim(txtInquiryContent(2).Text) = "" Then
MsgBox "请将第三行选项内容填写完整!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Else
txtSQL = txtSQL & " " & Relationname(comboCombineRelation(1).Text) & " " & FiledName(comboField(2).Text) & " " & Trim(comboOpSign(2).Text) & "'" & Trim(txtInquiryContent(2).Text) & "'"
End If
End If
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = True Then
MsgBox "没有您要查找的教师,请重新填写!", vbOKOnly + vbExclamation, "警告"
Else
With MSHFlexGrid1
.CellAlignment = 4
.Rows = 1
.ColWidth(2) = 1900
.ColWidth(4) = 1900
.TextMatrix(0, 0) = "教师"
.TextMatrix(0, 1) = "注册日期"
.TextMatrix(0, 2) = "注册时间"
.TextMatrix(0, 3) = "注销日期"
.TextMatrix(0, 4) = "注销时间"
.TextMatrix(0, 5) = "机器名"
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(1) & ""
.TextMatrix(.Rows - 1, 1) = mrc.Fields(3) & ""
.TextMatrix(.Rows - 1, 2) = mrc.Fields(4) & ""
.TextMatrix(.Rows - 1, 3) = mrc.Fields(5) & ""
.TextMatrix(.Rows - 1, 4) = mrc.Fields(6) & ""
.TextMatrix(.Rows - 1, 5) = mrc.Fields(7) & ""
mrc.MoveNext
Loop
End With
End If
mrc.Close
End If
End Sub
三、自己写的代码,可能有BUG,欢迎指正。