⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 Visual Basic开发实用编程200例 数据库编程实例
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "学生名册管理"
   ClientHeight    =   4380
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5235
   LinkTopic       =   "Form1"
   ScaleHeight     =   4380
   ScaleWidth      =   5235
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command6 
      Caption         =   "结束&E"
      Height          =   375
      Left            =   3960
      TabIndex        =   13
      Top             =   2640
      Width           =   1095
   End
   Begin VB.CommandButton Command5 
      Caption         =   "取消&C"
      Height          =   375
      Left            =   3960
      TabIndex        =   12
      Top             =   2160
      Width           =   1095
   End
   Begin VB.CommandButton Command4 
      Caption         =   "保存&S"
      Height          =   375
      Left            =   3960
      TabIndex        =   11
      Top             =   1680
      Width           =   1095
   End
   Begin VB.CommandButton Command3 
      Caption         =   "删除&D"
      Height          =   375
      Left            =   3960
      TabIndex        =   10
      Top             =   1200
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "添加&A"
      Height          =   375
      Left            =   3960
      TabIndex        =   9
      Top             =   720
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "搜索&F"
      Height          =   375
      Left            =   3960
      TabIndex        =   8
      Top             =   240
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      DataField       =   "电话号码"
      DataSource      =   "Data1"
      Height          =   375
      Index           =   3
      Left            =   960
      TabIndex        =   3
      Text            =   "Text1"
      Top             =   2400
      Width           =   2775
   End
   Begin VB.TextBox Text1 
      DataField       =   "生日"
      DataSource      =   "Data1"
      Height          =   375
      Index           =   2
      Left            =   960
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   1680
      Width           =   2775
   End
   Begin VB.TextBox Text1 
      DataField       =   "名字"
      DataSource      =   "Data1"
      Height          =   375
      Index           =   1
      Left            =   960
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   960
      Width           =   2775
   End
   Begin VB.TextBox Text1 
      DataField       =   "学号"
      DataSource      =   "Data1"
      Height          =   375
      Index           =   0
      Left            =   960
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   240
      Width           =   2775
   End
   Begin VB.Data Data1 
      Caption         =   "Data1"
      Connect         =   "Access"
      DatabaseName    =   "G:\写书\核心实例\学生名册管理系统\student.mdb"
      DefaultCursorType=   0  '缺省游标
      DefaultType     =   2  '使用 ODBC
      Exclusive       =   0   'False
      Height          =   405
      Left            =   480
      Options         =   0
      ReadOnly        =   0   'False
      RecordsetType   =   1  'Dynaset
      RecordSource    =   "学生名册"
      Top             =   3480
      Width           =   3900
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "电话"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Index           =   3
      Left            =   360
      TabIndex        =   7
      Top             =   2400
      Width           =   420
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "生日"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Index           =   2
      Left            =   360
      TabIndex        =   6
      Top             =   1680
      Width           =   420
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "姓名"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Index           =   1
      Left            =   360
      TabIndex        =   5
      Top             =   960
      Width           =   420
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "学号"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   210
      Index           =   0
      Left            =   360
      TabIndex        =   4
      Top             =   240
      Width           =   420
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click() '搜索
Dim MyNumber As String
'输入搜索的学号
MyNumber = InputBox$("请输入学号(6位)", "学号搜索", "990001")
If MyNumber <> "" Then
'输入字符串不能空,且按下确定按钮
Data1.Recordset.FindFirst "学号='" & MyNumber & "'"
 '组合搜索字符串
End If
End Sub

Private Sub Command2_Click()  '添加
  Dim i As Integer
  
  On Error GoTo AppErr

  Data1.Recordset.AddNew   '添加一组记录数据
  For i = 0 To 3
     Text1(i).Text = "" '清除文本框内容
  Next
  
  Exit Sub    '跳离本程序
  
AppErr:
  MsgBox Err.Description  '显示错误信息
End Sub

Private Sub Command3_Click() '删除
On Error GoTo DelErr
Dim s As String
'创建删除确认窗口
s = MsgBox("确定删除这组记录吗?", vbQuestion + vbOKCancel, "删除确定")
If s = 1 Then '确定删除记录数据
  Data1.Recordset.Delete  '删除记录
  Data1.Recordset.MoveNext  '移至下一记录
                          '是否还有记录
  If Data1.Recordset.RecordCount > 0 Then
    If Data1.Recordset.EOF Then
    Data1.Recordset.MoveLast
    End If
    
  End If
  
End If

Exit Sub

DelErr:
Rollback
 MsgBox Err.Description  '显示错误信息
End Sub

Private Sub Command4_Click()  '保存
  Dim Position As Variant
  Dim s As String
  On Error GoTo UpdateErr
  BeginTrans
    Data1.Recordset.Update   '数据写入数据库
  CommitTrans
  Data1.Refresh
  Exit Sub
UpdateErr:
  Rollback
  MsgBox Err.Description   '显示错误信息
End Sub

Private Sub Command5_Click()  '取消
  On Error GoTo CancelErr
  Data1.Recordset.CancelUpdate  '取消写入数据
  Exit Sub
CancelErr:
  MsgBox Err.Description
End Sub

Private Sub Command6_Click()
End
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -