##前言
####机房中的组合查询是一个小难点,说难绝对是你没画流程图,画完流程图思路清晰敲代码很容易上手啊,可见流程图的重要性。机房系统中有三个组合查询窗体,在这就不一一列举了,以学生基本信息窗体为例。这个窗体中的修改也是一项小难点,难在单机选中整行信息进行修改。看完这篇文章你会发现其实很容易!
####部分代码片段
组合查询代码
Private Sub cmdInquiry_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
txtSQL = "select * from student_info where "
Set mrc = ExecuteSQL(txtSQL, MsgText)
If Trim(comFields1(0).Text) = "" Or Trim(comOperator1(0).Text) = "" Or Trim(txtInquiry1(0).Text) = "" Then
MsgBox "请将第一行内容补充完整!", 48, "警告"
Else
txtSQL = txtSQL & " " & field(comFields1(0).Text) & "" & comOperator1(0).Text & " '" & Trim(txtInquiry1(0).Text) & "'"
If Trim(comGroup1(0).Text) <> "" Then
If Trim(comFields1(1).Text) = "" Or Trim(comOperator1(1).Text) = "" Or Trim(txtInquiry1(1).Text) = "" Then
MsgBox "请将第二行内容补充完整!", 48, "警告"
Else
txtSQL = txtSQL & " " & field(comGroup1(0).Text) & " " & field(comFields1(1).Text) & "" & comOperator1(1).Text & "'" & Trim(txtInquiry1(1).Text) & "'"
If Trim(comGroup1(1).Text) <> "" Then
If Trim(comFields1(2).Text) = "" Or Trim(comOperator1(2).Text) = "" Or Trim(txtInquiry1(2).Text) = "" Then
MsgBox "请将第三行内容补充完整!", 48, "警告"
Exit Sub
Else
txtSQL = txtSQL & " " & field(comGroup1(1).Text) & " " & field(comFields1(2).Text) & "" & comOperator1(2).Text & "'" & Trim(txtInquiry1(2).Text) & "'"
End If
End If
End If
End If
End If
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "无该数据,请重新填写!", 48, "警告"
txtInquiry1(0).SetFocus
txtInquiry1(0).Text = ""
MSFlexGrid1.Clear
Exit Sub
Else
With MSFlexGrid1
.Rows = 1
.CellAlignment = 4
.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) = "状态"
.TextMatrix(0, 9) = "备注"
.TextMatrix(0, 10) = "类型"
.TextMatrix(0, 11) = "日期"
.TextMatrix(0, 12) = "时间"
.TextMatrix(0, 13) = "是否选中"
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
.TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(2))
.TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(0))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(7))
.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(3))
.TextMatrix(.Rows - 1, 8) = Trim(mrc.Fields(10))
.TextMatrix(.Rows - 1, 9) = Trim(mrc.Fields(8))
.TextMatrix(.Rows - 1, 10) = Trim(mrc.Fields(14))
.TextMatrix(.Rows - 1, 11) = Trim(mrc.Fields(12))
.TextMatrix(.Rows - 1, 12) = Trim(mrc.Fields(13))
mrc.MoveNext
Loop
End With
End If
End Sub
修改信息
- 单机信息选中整行
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MSFlexGrid1.SelectionMode = flexSelectionByRow
MSFlexGrid1.FocusRect = flexFocusNone
MSFlexGrid1.Highlight = flexHighlightWithFocus
End Sub
- 在控件中加上是否选中列,选中会出现标识。
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
With MSFlexGrid1
If .MouseRow Then '选中当前行
.TextMatrix(.MouseRow, 13) = "*"
Exit Sub
End If
End With
End Sub
- 将控件中信息进行修改
Private Sub cmdModify_Click()
With MSFlexGrid1
If MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, 13) <> "*" Then
MsgBox "请先选择数据!", 48, "警告"
Exit Sub
Else
frmModifyStu.txtSID = .TextMatrix(.RowSel, 0)
frmModifyStu.txtName = .TextMatrix(.RowSel, 1)
frmModifyStu.comSex = .TextMatrix(.RowSel, 7)
frmModifyStu.txtDept = .TextMatrix(.RowSel, 4)
frmModifyStu.txtGrade = .TextMatrix(.RowSel, 5)
frmModifyStu.txtClassNo = .TextMatrix(.RowSel, 6)
frmModifyStu.txtCardNo = .TextMatrix(.RowSel, 2)
frmModifyStu.txtCash = .TextMatrix(.RowSel, 3)
frmModifyStu.txtState = .TextMatrix(.RowSel, 8)
frmModifyStu.txtExplain = .TextMatrix(.RowSel, 9)
frmModifyStu.comType = .TextMatrix(.RowSel, 10)
frmModifyStu.Show
End If
End With
End Sub