代码设计:
Private Sub CmdExec_Click()
If Combo1.ListIndex = -1 Or Combo2.ListIndex = -1 Or Combo3.ListIndex = -1 Then
MsgBox "请确保选择统计班级、学科和考试性质!"
Exit Sub
End If
DataOut
ExecPass
LoadData
End Sub
Private Sub ComLst_Click(Index As Integer)
If ComLst(Index).ListIndex > -1 And Combo3.ListIndex > -1 Then
Dim txtSQL As String
txtSQL = "select b.班级,b.学号,b.姓名,a.* from 成绩表 AS a INNER JOIN 学籍表 AS b ON a.考试号 = b.考试号 where 姓名 = '" & ComLst(Index).Text & "' and 考试性质 = '" & Combo3.Text & "'"
Adodc1.ConnectionString = Con.ConnectionString
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = txtSQL
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End If
End Sub
Private Sub Form_Load()
Call ResizeInit(Me)
Dim Rsb As ADODB.Recordset
Set Rsb = New ADODB.Recordset
Rsb.Open "select distinct b.班级 as KsBJ from 成绩表 AS a INNER JOIN 学籍表 AS b ON a.考试号 = b.考试号 ", Con, adOpenStatic, , adCmdText
Combo1.Clear
Do While Not Rsb.EOF
Combo1.AddItem Rsb!KsBJ
Rsb.MoveNext
Loop
Set Rsx = New ADODB.Recordset
Rsx.Open "select distinct a.考试性质 as Ksxz from 成绩表 AS a INNER JOIN 学籍表 AS b ON a.考试号 = b.考试号 ", Con, adOpenStatic, , adCmdText
Combo3.Clear
Do While Not Rsx.EOF
Combo3.AddItem Rsx!Ksxz
Rsx.MoveNext
Loop
If Combo1.ListCount > 0 Then
Combo1.ListIndex = 0
Combo2.ListIndex = 9
End If
If Combo3.ListCount > 0 Then
Combo3.ListIndex = 0
End If
End Sub