📄 frmxjadd.frm
字号:
VERSION 5.00
Begin VB.Form frmxjadd
Caption = "添加学籍信息"
ClientHeight = 5550
ClientLeft = 60
ClientTop = 345
ClientWidth = 7470
LinkTopic = "Form1"
ScaleHeight = 5550
ScaleWidth = 7470
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton cmdexit
Caption = "退出"
Height = 435
Left = 4410
TabIndex = 19
Top = 4920
Width = 1305
End
Begin VB.CommandButton cmdxjadd
Caption = "添加"
Height = 465
Left = 1710
TabIndex = 18
Top = 4890
Width = 1485
End
Begin VB.TextBox Text8
Height = 405
Left = 1290
TabIndex = 17
Top = 4170
Width = 5565
End
Begin VB.TextBox Text7
Height = 405
Left = 1290
TabIndex = 15
Top = 3420
Width = 5565
End
Begin VB.TextBox Text6
Height = 375
Left = 1290
TabIndex = 13
Top = 2640
Width = 5565
End
Begin VB.TextBox Text5
Height = 405
Left = 5100
TabIndex = 11
Top = 1950
Width = 1755
End
Begin VB.TextBox Text4
Height = 405
Left = 1290
TabIndex = 9
Top = 1890
Width = 1755
End
Begin VB.TextBox Text3
Height = 405
Left = 5130
TabIndex = 7
Top = 1170
Width = 1755
End
Begin VB.ComboBox Combo1
Height = 315
ItemData = "frmxjadd.frx":0000
Left = 1290
List = "frmxjadd.frx":0002
Style = 2 'Dropdown List
TabIndex = 5
Top = 1110
Width = 1425
End
Begin VB.TextBox Text2
Height = 405
Left = 5100
TabIndex = 1
Top = 390
Width = 1755
End
Begin VB.TextBox Text1
Height = 405
Left = 1290
TabIndex = 0
Top = 360
Width = 1755
End
Begin VB.Label Label9
Caption = "备注:"
Height = 405
Left = 600
TabIndex = 16
Top = 4170
Width = 675
End
Begin VB.Label Label8
Caption = "地址:"
Height = 405
Left = 600
TabIndex = 14
Top = 3408
Width = 675
End
Begin VB.Label Label7
Caption = "电话:"
Height = 405
Left = 600
TabIndex = 12
Top = 2646
Width = 675
End
Begin VB.Label Label6
Caption = "入学时间:"
Height = 465
Left = 3930
TabIndex = 10
Top = 1950
Width = 1215
End
Begin VB.Label Label5
Caption = "班级:"
Height = 405
Left = 600
TabIndex = 8
Top = 1884
Width = 675
End
Begin VB.Label Label4
Caption = "出生日期:"
Height = 465
Left = 3930
TabIndex = 6
Top = 1170
Width = 1215
End
Begin VB.Label Label3
Caption = "性别:"
Height = 405
Left = 600
TabIndex = 4
Top = 1122
Width = 675
End
Begin VB.Label Label2
Caption = "姓名:"
Height = 465
Left = 3930
TabIndex = 3
Top = 390
Width = 1215
End
Begin VB.Label Label1
Caption = "学号:"
Height = 405
Left = 600
TabIndex = 2
Top = 360
Width = 675
End
End
Attribute VB_Name = "frmxjadd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdxjadd_Click()
Dim mrc As ADODB.Recordset '定义数据集对象
Dim txtsql As String '定义查询字符串变量
Dim msgtext As String '定义字符串变量,用来返回查询信息
'判断是否输入了学号
If Trim(Text1.Text) = "" Then
MsgBox "请输入学号", vbOKOnly, "警告"
Text1.SetFocus
Exit Sub
End If
'判断是否输入了姓名
If Text2.Text = "" Then
MsgBox "请输入姓名", vbOKOnly, "警告"
Text2.SetFocus
Exit Sub
End If
'判断是否输入了出生日期
If Text3.Text = "" Then
MsgBox "请输入出生日期", vbOKOnly, "警告"
Text3.SetFocus
Exit Sub
End If
'判断输入的出生日期是否为正确格式
If Not IsDate(Text3.Text) Then
MsgBox "日期的正确格式应为(YYYY-MM-DD)", vbOKOnly, "警告"
Text3.SetFocus
Exit Sub
End If
'判断是否输入了班级
If Text4.Text = "" Then
MsgBox "请输入班级", vbOKOnly, "警告"
Text4.SetFocus
Exit Sub
End If
'判断是否输入了入学时间
If Text5.Text = "" Then
MsgBox "请输入入学时间", vbOKOnly, "警告"
Text5.SetFocus
Exit Sub
End If
'判断输入的入学时间是否为正确格式
If Not IsDate(Text5.Text) Then
MsgBox "日期的正确格式应为(YYYY-MM-DD)", vbOKOnly, "警告"
Text5.SetFocus
Exit Sub
End If
'根据学号判断数据库中是否有重复的记录
txtsql = "select * from student_info where student_ID='" & Trim(Text1.Text) & "'"
Set mrc = ExecuteSQL(txtsql, msgtext)
If mrc.EOF = False Then
MsgBox "学号重复,请重新输入!", vbOKOnly, "警告"
mrc.Close
Text1.SetFocus
Else '添加一条记录进入数据库中
mrc.AddNew
mrc.Fields("student_ID") = Trim(Text1.Text)
mrc.Fields("student_name") = Trim(Text2.Text)
mrc.Fields("student_sex") = Combo1.Text
mrc.Fields("born_date") = Format(Text3.Text, "yyyy-mm-dd")
mrc.Fields("classname") = Trim(Text4.Text)
mrc.Fields("enroll_date") = Format(Text5.Text, "yyyy-mm-dd")
mrc.Fields("telephone") = Trim(Text6.Text)
mrc.Fields("address") = Trim(Text7.Text)
mrc.Fields("comment") = Trim(Text8.Text)
mrc.Update
MsgBox "添加数据成功", vbOKOnly, "提示"
mrc.Close
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "男"
Combo1.AddItem "女"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -