📄 form_search.frm
字号:
Top = 360
Width = 735
End
Begin VB.CheckBox Check2
Caption = "姓名"
Height = 375
Left = 960
TabIndex = 10
Top = 360
Width = 735
End
Begin VB.CheckBox Check3
Caption = "系别"
Height = 375
Left = 1680
TabIndex = 9
Top = 360
Width = 735
End
Begin VB.CheckBox Check4
Caption = "住址"
Height = 375
Left = 2400
TabIndex = 8
Top = 360
Width = 735
End
Begin VB.CheckBox Check5
Caption = "电话"
Height = 255
Left = 240
TabIndex = 7
Top = 720
Width = 855
End
Begin VB.CheckBox Check7
Caption = "学分"
Height = 255
Left = 1680
TabIndex = 6
Top = 720
Width = 735
End
Begin VB.CheckBox Check8
Caption = "成绩"
Height = 255
Left = 2400
TabIndex = 5
Top = 720
Width = 855
End
Begin VB.CheckBox Check9
Caption = "课程名称"
Height = 375
Left = 240
TabIndex = 4
Top = 960
Width = 1335
End
Begin VB.CheckBox Check10
Caption = "任课老师"
Height = 375
Left = 1680
TabIndex = 3
Top = 960
Width = 1455
End
Begin VB.Label Label20
Caption = "按照:"
Height = 255
Left = 3840
TabIndex = 18
Top = 525
Width = 615
End
Begin VB.Label Label21
Caption = "以:"
Height = 255
Left = 3840
TabIndex = 17
Top = 1080
Width = 495
End
Begin VB.Label Label22
Caption = "排列"
Height = 255
Left = 6000
TabIndex = 16
Top = 1080
Width = 495
End
End
Begin VB.CommandButton Comm_sear_goon
Caption = "继续查询"
Height = 375
Left = 5520
TabIndex = 1
Top = 4440
Visible = 0 'False
Width = 1215
End
End
End
Attribute VB_Name = "Form_search"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'======================= 返回及续继查找 =================================
Private Sub Comm_sear_goon_Click()
Frame_sear1.Visible = True '使三个查询Frame均在可见状态下
Frame_sear2.Visible = True
Frame_sear3.Visible = True
Frame_result1.Visible = False '查询结果Frame均在不可见状态下
Frame_result2.Visible = False
Frame_result3.Visible = False
Comm_sear_goon.Visible = False
End Sub
Private Sub Command1_Click()
main.Visible = True
Form_search.Visible = False
End Sub
'================================================================
'======================= 初始化 =================================
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + App.Path + "\MDB\成绩管理.mdb"
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + App.Path + "\MDB\成绩管理.mdb"
Adodc3.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + App.Path + "\MDB\成绩管理.mdb"
Adodc_sour.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" + App.Path + "\MDB\成绩管理.mdb"
End Sub
'================================================================
'======================= 第一项查找 =============================
Private Sub Comm_sear1_Click() '第一项查找
On Error Resume Next
Frame_sear1.Visible = False
Frame_sear2.Visible = False
Frame_sear3.Visible = False
Frame_result1.Visible = True '查询结果1可见
Frame_result2.Visible = False
Frame_result3.Visible = False
Comm_sear_goon.Visible = True '继续查找按钮可见
Dim search As String
If Option1.Value = True Then
search = "select * from 查询1 where 学号 =" & Text_key.Text '按学号查询
Else
search = "select * from 查询1 where 姓名 like '" & Text_key.Text & "'" '按姓名查询
End If
With Adodc1
.RecordSource = search '将查询条件赋于Adodc1
.Refresh
End With
With DataGrid1
.Columns(0).Visible = False
.Columns(1).Visible = False '使学号,姓名,系别三项隐藏不显示
.Columns(2).Visible = False
End With
End Sub
'===================================================================
'========================== 第二项查找 =============================
Private Sub Comm_sear2_Click() '第二项查找
On Error Resume Next
Frame_sear1.Visible = False
Frame_sear2.Visible = False
Frame_sear3.Visible = False
Frame_result1.Visible = False
Frame_result2.Visible = True '查询结果2可见
Frame_result3.Visible = False
Comm_sear_goon.Visible = True '继续查找按钮可见
Dim search2 As String
Select Case Combo_con.Text '成绩的比较条件
Case "大于"
search2 = "select * from 查询2 where 课程名称 = '" & DataCombo_sour.Text & "' and 成绩 > " & Text_num.Text '在查询2视图里查找课程名为DataCombo_sour.Text,且成绩符合条件的记录
Case "等于"
search2 = "select * from 查询2 where 课程名称 = '" & DataCombo_sour.Text & "' and 成绩 = " & Text_num.Text
Case "小于"
search2 = "select * from 查询2 where 课程名称 = '" & DataCombo_sour.Text & "' and 成绩 < " & Text_num.Text
Case ">="
search2 = "select * from 查询2 where 课程名称 = '" & DataCombo_sour.Text & "' and 成绩 >= " & Text_num.Text
Case "<="
search2 = "select * from 查询2 where 课程名称 = '" & DataCombo_sour.Text & "' and 成绩 <= " & Text_num.Text
End Select
With Adodc2
.RecordSource = search2 '重新定义adodc2的数据来源,将SQL语句查到的结果赋给adodc2
.Refresh
End With
End Sub
'======================================================================
'========================== 联合视图 ================================
Private Sub Comm_sear3_Click() '联合视图
On Error Resume Next
intgrid '使视图的各个列处于不可视状态下
Frame_sear1.Visible = False
Frame_sear2.Visible = False
Frame_sear3.Visible = False
Frame_result1.Visible = False
Frame_result2.Visible = False
Frame_result3.Visible = True '查询结果3可见
Comm_sear_goon.Visible = True '继续查找按钮可见
jubgrid '判断哪些列被选中了
Dim search3 As String
If Option3.Visible = True Then '按升序排列记录
Select Case Combo3.Text
Case "学号"
search3 = "select * from 查询3 order by 学号 ASC"
Case "学分"
search3 = "select * from 查询3 order by 学分 ASC" '按哪项来排列记录
Case "成绩"
search3 = "select * from 查询3 order by 成绩 ASC"
End Select
Else '按降序来排列记录
Select Case Combo3.Text
Case "学号"
search3 = "select * from 查询3 order by 学号 DESC"
Case "学分"
search3 = "select * from 查询3 order by 学分 DESC"
Case "成绩"
search3 = "select * from 查询3 order by 成绩 DESC"
End Select
End If
With Adodc3
.RecordSource = search3
.Refresh
End With
End Sub
'=========================================================================
'=========================== 联合视图各项隐藏 ===========================
Private Sub intgrid()
With DataGrid3
.Columns(0).Visible = False
.Columns(1).Visible = False
.Columns(2).Visible = False
.Columns(3).Visible = False
.Columns(4).Visible = False
.Columns(5).Visible = False
.Columns(6).Visible = False
.Columns(7).Visible = False
.Columns(8).Visible = False
.Columns(9).Visible = False
End With
End Sub
Private Sub jubgrid()
If Check1.Value = 1 Then '当某个字段被添加后,在Dbgrid中的相应列的隐藏属性都去掉.
With DataGrid3
.Columns(0).Visible = True
End With
End If
If Check2.Value = 1 Then
With DataGrid3
.Columns(1).Visible = True
End With
End If
If Check8.Value = 1 Then
With DataGrid3
.Columns(7).Visible = True
End With
End If
If Check6.Value = 1 Then
With DataGrid3
.Columns(6).Visible = True
End With
End If
If Check6.Value = 1 Then
With DataGrid3
.Columns(5).Visible = True
End With
End If
If Check5.Value = 1 Then
With DataGrid3
.Columns(4).Visible = True
End With
End If
If Check4.Value = 1 Then
With DataGrid3
.Columns(3).Visible = True
End With
End If
If Check3.Value = 1 Then
With DataGrid3
.Columns(2).Visible = True
End With
End If
End Sub
'=========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -