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

📄 validatebound.frm

📁 VB6数据库开发指南》的配套源程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H00C0C0C0&
   Caption         =   "Validate Bound"
   ClientHeight    =   2460
   ClientLeft      =   1440
   ClientTop       =   2325
   ClientWidth     =   6420
   BeginProperty Font 
      Name            =   "MS Sans Serif"
      Size            =   8.25
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2460
   ScaleWidth      =   6420
   Begin VB.TextBox txtBirthDate 
      DataField       =   "BirthDate"
      DataSource      =   "datEmployees"
      Height          =   285
      Left            =   1800
      TabIndex        =   6
      Top             =   720
      Width           =   2055
   End
   Begin VB.TextBox txtEmployeeId 
      DataField       =   "EmployeeID"
      DataSource      =   "datEmployees"
      Enabled         =   0   'False
      Height          =   285
      Left            =   1800
      TabIndex        =   4
      Top             =   1200
      Width           =   1935
   End
   Begin VB.TextBox txtEmpFirstName 
      DataField       =   "FirstName"
      DataSource      =   "datEmployees"
      Height          =   285
      Left            =   3960
      TabIndex        =   1
      Top             =   240
      Width           =   2055
   End
   Begin VB.TextBox txtEmpLastName 
      DataField       =   "LastName"
      DataSource      =   "datEmployees"
      Height          =   285
      Left            =   1800
      MultiLine       =   -1  'True
      TabIndex        =   0
      Top             =   240
      Width           =   2055
   End
   Begin VB.Data datEmployees 
      Caption         =   "Employees"
      Connect         =   "Access"
      DatabaseName    =   "D:\Program Files\Microsoft Visual Studio\VB6\Nwind.mdb"
      DefaultCursorType=   0  'DefaultCursor
      DefaultType     =   2  'UseODBC
      Exclusive       =   0   'False
      Height          =   465
      Left            =   360
      Options         =   0
      ReadOnly        =   0   'False
      RecordsetType   =   1  'Dynaset
      RecordSource    =   "Employees"
      Top             =   1800
      Width           =   2535
   End
   Begin VB.Label Label2 
      Caption         =   "Birth Date:"
      Height          =   255
      Left            =   360
      TabIndex        =   5
      Top             =   720
      Width           =   975
   End
   Begin VB.Label Label3 
      Caption         =   "Employee ID:"
      Height          =   255
      Left            =   360
      TabIndex        =   3
      Top             =   1200
      Width           =   1215
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackColor       =   &H00C0C0C0&
      Caption         =   "Employee:"
      Height          =   195
      Left            =   360
      TabIndex        =   2
      Top             =   240
      Width           =   885
   End
   Begin VB.Menu mnuFile 
      Caption         =   "&File"
      Begin VB.Menu mnuFileExit 
         Caption         =   "E&xit"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Utility As New clsUtility
Private mblnValidationFailed As Boolean

Private Sub datEmployees_Validate(Action As Integer, Save As Integer)
    Dim strMsg As String
    Dim enumMsgResult As VbMsgBoxResult
        
    If Save = True Or Action = vbDataActionUpdate _
    Or Action = vbDataActionUnload Then
        ' One or more bound controls has changed or a previous
        ' validation failed, so verify that all fields have legal
        ' entries. If a field has an incorrect value, appenda
        ' string explaining the error to strMsg and set the focus
        ' to that field to facilitate correcting the error. We
        ' explain all errors encountered in a single message box.
        strMsg = ""
        If txtEmpLastName.Text = "" Then
             Utility.AddToMsg strMsg, "You must enter a last name."
             txtEmpLastName.SetFocus
        End If
        If txtEmpFirstName.Text = "" Then
             Utility.AddToMsg strMsg, "You must enter a first name."
             txtEmpFirstName.SetFocus
        End If
        If Not IsDate(txtBirthDate.Text) Then
             Utility.AddToMsg strMsg, "You must enter a birth date."
             txtBirthDate.SetFocus
        Else
            If CDate(txtBirthDate.Text) >= Date Then
                 Utility.AddToMsg strMsg, _
                    "Birth date must be in the past."
                 txtBirthDate.SetFocus
            End If
        End If
        
        If strMsg <> "" Then
             ' We have something in the variable strMsg, which
             ' means that an error has occurred. Display the
             ' message. The focus is in the last text box where
             ' an error was found.
             MsgBox strMsg, vbExclamation
             ' Cancel the Validate event
             Action = vbDataActionCancel
             ' Deny form Unload until fields are corrected
             mblnValidationFailed = True
         Else
             mblnValidationFailed = False
         End If
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    ' Don't allow the unload until the data is validated.
    If mblnValidationFailed Then Cancel = True
End Sub

Private Sub mnuFileExit_Click()
    Unload Me
End Sub

⌨️ 快捷键说明

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