📄 form2.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form2
AutoRedraw = -1 'True
BorderStyle = 3 'Fixed Dialog
Caption = "学生登记"
ClientHeight = 5985
ClientLeft = 2790
ClientTop = 2085
ClientWidth = 6885
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 5985
ScaleWidth = 6885
ShowInTaskbar = 0 'False
Begin VB.Frame Frame1
Caption = "学生信息登记"
Height = 3015
Left = 120
TabIndex = 1
Top = 120
Width = 6615
Begin VB.CommandButton Command3
BackColor = &H00FF8080&
Caption = "退出"
Height = 375
Left = 5640
Style = 1 'Graphical
TabIndex = 16
Top = 2160
Width = 735
End
Begin VB.CommandButton Command2
BackColor = &H00FF8080&
Caption = "保存"
Height = 375
Left = 5640
Style = 1 'Graphical
TabIndex = 15
Top = 960
Width = 735
End
Begin VB.CommandButton Command1
BackColor = &H00FF8080&
Caption = "添加"
Height = 375
Left = 5640
Style = 1 'Graphical
TabIndex = 14
Top = 480
Width = 735
End
Begin VB.TextBox Text3
Height = 615
Left = 1200
TabIndex = 13
Top = 1920
Width = 3975
End
Begin VB.TextBox Text4
Height = 270
Left = 1200
TabIndex = 11
Top = 1440
Width = 1815
End
Begin VB.TextBox Text5
Height = 270
Left = 3600
TabIndex = 9
Top = 960
Width = 1575
End
Begin VB.ComboBox Combo1
Height = 300
ItemData = "Form2.frx":0000
Left = 3600
List = "Form2.frx":000A
TabIndex = 7
Top = 480
Width = 1575
End
Begin VB.TextBox Text2
Height = 270
Left = 960
TabIndex = 5
Top = 960
Width = 1455
End
Begin VB.TextBox Text1
Height = 270
Left = 960
TabIndex = 4
Top = 480
Width = 1455
End
Begin VB.Label Label7
Caption = "家庭地址:"
Height = 255
Left = 360
TabIndex = 12
Top = 1920
Width = 855
End
Begin VB.Label Label5
Caption = "出生年月:"
Height = 255
Left = 360
TabIndex = 10
Top = 1440
Width = 975
End
Begin VB.Label Label4
Caption = "专业:"
Height = 255
Left = 3000
TabIndex = 8
Top = 960
Width = 615
End
Begin VB.Label Label3
Caption = "性别:"
Height = 255
Left = 3000
TabIndex = 6
Top = 480
Width = 615
End
Begin VB.Label Label2
Caption = "姓名:"
Height = 255
Left = 360
TabIndex = 3
Top = 960
Width = 615
End
Begin VB.Label Label1
Caption = "学号:"
Height = 255
Left = 360
TabIndex = 2
Top = 480
Width = 735
End
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 5160
Top = 6120
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin MSHierarchicalFlexGridLib.MSHFlexGrid MSHFlexGrid1
Height = 2655
Left = 120
TabIndex = 0
Top = 3240
Width = 6615
_ExtentX = 11668
_ExtentY = 4683
_Version = 393216
_NumberOfBands = 1
_Band(0).Cols = 2
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Private Sub Command1_Click()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Combo1.Enabled = True
Command1.Enabled = False
Command2.Enabled = True
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Combo1.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Rs.AddNew
End Sub
Private Sub Command2_Click()
Dim Txtsql As String
Dim Mrc As ADODB.Recordset
'检查输入学号是否在数据库中有同名记录
If Trim(Text1.Text) = "" Then
MsgBox "请输入学号!", vbExclamation, "出错啦!"
Exit Sub
Else
Txtsql = "select * from 学生基本信息表"
Set Mrc = ExecuteSQL(Txtsql)
While (Mrc.EOF = False)
If Trim(Mrc.Fields(0)) = Trim(Text1.Text) Then
MsgBox "这个学号已经存在,请重新输入!", , "出错啦!"
Text1.Text = ""
Exit Sub
Else
Mrc.MoveNext
End If
Wend
End If
Rs("学号") = Text1.Text
Rs("姓名") = Text2.Text
Rs("性别") = Combo1.Text
Rs("家庭地址") = Text3.Text
If Text4.Text <> "" Then
Rs("出生年月") = Text4.Text
Else
End If
Rs("专业") = Text5.Text
Rs.Update
Command1.Enabled = True
Command2.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Combo1.Enabled = False
End Sub
Private Sub Command3_Click()
Unload Me
Set Rs = Nothing
Set Conn = Nothing
End Sub
Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Combo1.Enabled = False
Command2.Enabled = False
connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\学生信息管理.mdb"
Conn.Open connstr
Rs.Open "学生基本信息表", Conn, adOpenKeyset, adLockPessimistic
Call Showdata(Rs, MSHFlexGrid1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text4.SetFocus
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command2.SetFocus
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -