📄 frmstudent.frm
字号:
VERSION 5.00
Begin VB.Form FrmStudent
BorderStyle = 1 'Fixed Single
Caption = "学生"
ClientHeight = 4995
ClientLeft = 45
ClientTop = 330
ClientWidth = 6075
Icon = "FrmStudent.frx":0000
LinkTopic = "Form9"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4995
ScaleWidth = 6075
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton CmdAdd
Caption = "添加"
Height = 495
Left = 480
TabIndex = 23
Top = 4200
Width = 735
End
Begin VB.CommandButton CmdDelete
Caption = "删除"
Height = 495
Left = 1320
TabIndex = 22
Top = 4200
Width = 735
End
Begin VB.CommandButton CmdEdit
Caption = "修改"
Height = 495
Left = 2160
TabIndex = 21
Top = 4200
Width = 735
End
Begin VB.CommandButton CmdRefresh
Caption = "刷新"
Height = 495
Left = 3000
TabIndex = 20
Top = 4200
Width = 735
End
Begin VB.CommandButton CmdCourse
Caption = "返回课程主窗体"
Height = 495
Left = 3960
TabIndex = 19
Top = 4200
Width = 1695
End
Begin VB.ListBox ListName
Height = 3660
ItemData = "FrmStudent.frx":030A
Left = 3960
List = "FrmStudent.frx":030C
TabIndex = 18
Top = 480
Width = 1695
End
Begin VB.TextBox TextSurname
Height = 330
Left = 1440
TabIndex = 17
Top = 1112
Width = 1335
End
Begin VB.TextBox TextName
Height = 330
Left = 1440
TabIndex = 16
Top = 676
Width = 1335
End
Begin VB.TextBox TextID
Height = 330
Left = 1440
TabIndex = 6
Top = 240
Width = 855
End
Begin VB.TextBox TextMajor
Height = 330
Left = 1440
TabIndex = 5
Top = 1548
Width = 1695
End
Begin VB.TextBox TextTelephone
Height = 330
Left = 1440
TabIndex = 4
Top = 2055
Width = 1695
End
Begin VB.TextBox TextAddress
Height = 330
Left = 1440
TabIndex = 3
Top = 2490
Width = 2295
End
Begin VB.TextBox TextPostcode
Height = 330
Left = 1440
TabIndex = 2
Top = 3810
Width = 1575
End
Begin VB.TextBox TextCity
Height = 330
Left = 1440
TabIndex = 1
Top = 2925
Width = 2295
End
Begin VB.TextBox TextProvince
Height = 330
Left = 1440
TabIndex = 0
Top = 3375
Width = 2295
End
Begin VB.Label Label6
Caption = "学生名单"
Height = 255
Left = 3960
TabIndex = 24
Top = 240
Width = 735
End
Begin VB.Label Label1
Caption = "学生 ID"
Height = 255
Left = 480
TabIndex = 15
Top = 300
Width = 735
End
Begin VB.Label Label2
Caption = "名字"
Height = 255
Left = 480
TabIndex = 14
Top = 735
Width = 735
End
Begin VB.Label Label3
Caption = "姓氏"
Height = 255
Left = 480
TabIndex = 13
Top = 1170
Width = 735
End
Begin VB.Label Label4
Caption = "主修"
Height = 255
Left = 480
TabIndex = 12
Top = 1605
Width = 735
End
Begin VB.Label Label5
Caption = "电话号码"
Height = 255
Left = 480
TabIndex = 11
Top = 2115
Width = 735
End
Begin VB.Label Label7
Caption = "地址"
Height = 255
Left = 480
TabIndex = 10
Top = 2550
Width = 735
End
Begin VB.Label Label8
Caption = "邮政编码"
Height = 255
Left = 480
TabIndex = 9
Top = 3855
Width = 735
End
Begin VB.Label Label9
Caption = "城市"
Height = 255
Left = 480
TabIndex = 8
Top = 2985
Width = 735
End
Begin VB.Label Label10
Caption = "省份"
Height = 255
Left = 480
TabIndex = 7
Top = 3420
Width = 735
End
End
Attribute VB_Name = "FrmStudent"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ix As Index
Dim rs As Recordset
Private Sub cmdAdd_Click()
On Error GoTo errhandle:
rs.Edit
rs.AddNew
Call SaveRecord
rs.Fields("学生ID").Value = Me.TextID.Text + ""
rs.Update
rs.MoveLast
Call RefreshList
Exit Sub
errhandle:
MsgBox Err.Description
End Sub
Private Sub CmdCourse_Click()
Unload Me
FrmCourse.Show
End Sub
Private Sub CmdDelete_Click()
On Error GoTo errhandle:
rs.Edit
rs.Delete
rs.Update
'If Not rs.EOF Then
'rs.MoveNext
'Else
'rs.MovePrevious
'End If
'Debug.Print rs.Bookmark
rs.MoveNext
Call RefreshRecord
Call RefreshList
Exit Sub
errhandle:
MsgBox Err.Description
End Sub
Private Sub CmdEdit_Click()
On Error GoTo errhandle:
rs.Edit
Call SaveRecord
rs.Update
Call RefreshList
Exit Sub
errhandle:
MsgBox Err.Description
End Sub
Private Sub CmdRefresh_Click()
Call RefreshRecord
End Sub
Private Sub Form_Load()
Set rs = db.OpenRecordset("学生")
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Me.ListName.AddItem rs.Fields("名字").Value
rs.MoveNext
Next
rs.MoveFirst
Call RefreshRecord
End Sub
Private Function RefreshList()
Dim temp As String
Me.ListName.Clear
temp = rs.Bookmark
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Me.ListName.AddItem rs.Fields("名字").Value
rs.MoveNext
Next
rs.Bookmark = temp
End Function
Private Function SaveRecord()
rs.Fields("地址").Value = Me.TextAddress.Text & ""
rs.Fields("城市").Value = Me.TextCity.Text & ""
rs.Fields("主修").Value = Me.TextMajor.Text & ""
rs.Fields("名字").Value = Me.TextName.Text & ""
rs.Fields("邮政编码").Value = Me.TextPostcode.Text & ""
rs.Fields("省份").Value = Me.TextProvince.Text & ""
rs.Fields("姓氏").Value = Me.TextSurname.Text & ""
rs.Fields("电话号码").Value = Me.TextTelephone.Text & ""
End Function
Private Function RefreshRecord()
If rs.BOF Then rs.MoveFirst
If rs.EOF Then rs.MoveLast
Me.TextAddress.Text = rs.Fields("地址").Value & ""
Me.TextCity.Text = rs.Fields("城市").Value & ""
Me.TextID.Text = rs.Fields("学生ID").Value & ""
Me.TextMajor.Text = rs.Fields("主修").Value & ""
Me.TextName.Text = rs.Fields("名字").Value & ""
Me.TextPostcode.Text = rs.Fields("邮政编码").Value & ""
Me.TextProvince.Text = rs.Fields("省份").Value & ""
Me.TextSurname.Text = rs.Fields("姓氏").Value & ""
Me.TextTelephone.Text = rs.Fields("电话号码").Value & ""
End Function
Private Sub ListName_Click()
rs.Index = "名字"
rs.Seek "=", Me.ListName.Text
Call RefreshRecord
End Sub
Private Sub ListName_DblClick()
rs.Index = "名字"
rs.Seek "=", Me.ListName.Text
Call RefreshRecord
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -