📄 listbound.frm
字号:
VERSION 5.00
Object = "{FAEEE763-117E-101B-8933-08002B2F4F5A}#1.1#0"; "DBLIST32.OCX"
Begin VB.Form Form1
BackColor = &H00C0C0C0&
Caption = "Bound Lister"
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.Data datCategories
Caption = "Categories"
Connect = "Access"
DatabaseName = "D:\Program Files\Microsoft Visual Studio\VB6\Nwind.mdb"
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 465
Left = 3360
Options = 0
ReadOnly = 0 'False
RecordsetType = 2 'Snapshot
RecordSource = "Categories"
Top = 1800
Visible = 0 'False
Width = 2535
End
Begin MSDBCtls.DBCombo dbcCategory
Bindings = "ListBound.frx":0000
DataField = "CategoryID"
DataSource = "datProducts"
Height = 315
Left = 1800
TabIndex = 3
Top = 720
Width = 2055
_ExtentX = 3625
_ExtentY = 556
_Version = 327680
Style = 2
ListField = "CategoryName"
BoundColumn = "CategoryID"
Text = ""
End
Begin VB.TextBox txtProductName
DataField = "ProductName"
DataSource = "datProducts"
Height = 285
Left = 1800
MultiLine = -1 'True
TabIndex = 0
Top = 240
Width = 2055
End
Begin VB.Data datProducts
Caption = "Products"
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 = "Products"
Top = 1800
Width = 2535
End
Begin VB.Label Label2
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Category:"
Height = 195
Left = 360
TabIndex = 2
Top = 720
Width = 825
End
Begin VB.Label Label1
AutoSize = -1 'True
BackColor = &H00C0C0C0&
Caption = "Product Name:"
Height = 195
Left = 360
TabIndex = 1
Top = 240
Width = 1275
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFileExit
Caption = "E&xit"
End
End
Begin VB.Menu mnuEdit
Caption = "&Edit"
Begin VB.Menu mnuEditUndo
Caption = "&Undo"
Shortcut = ^Z
End
End
Begin VB.Menu mnuData
Caption = "&Data"
Begin VB.Menu mnuDataAdd
Caption = "&Add Record"
End
Begin VB.Menu mnuDataDelete
Caption = "&Delete Record"
End
Begin VB.Menu mnuDataSave
Caption = "&Save Record"
Enabled = 0 'False
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 datProducts_Validate(Action As Integer, Save As Integer)
Dim strMsg As String
Dim enumMsgResult As VbMsgBoxResult
If Save = True Or Action = vbDataActionUpdate _
Or mblnValidationFailed Or Action = vbDataActionAddNew 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 txtProductName.Text = "" Then
Utility.AddToMsg strMsg, "You must enter a Product name."
txtProductName.SetFocus
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
enumMsgResult = MsgBox(strMsg, vbExclamation + vbOKCancel + _
vbDefaultButton1)
If enumMsgResult = vbCancel Then
'Restore the data to previous values using the data control
datProducts.UpdateControls
mblnValidationFailed = False
Else
' Cancel the Validate event
Action = vbDataActionCancel
' Deny form Unload until fields are corrected
mblnValidationFailed = True
End If
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 validate or the
' update is cancelled
If mblnValidationFailed Then Cancel = True
End Sub
Private Sub mnuDataAdd_Click()
' Reset all controls to the default for a new record
' and make space for the record in the recordset copy
' buffer.
datProducts.Recordset.AddNew
'Enable the save menu choice
mnuDataSave.Enabled = True
' Set the focus to the first control on the form
txtProductName.SetFocus
End Sub
Private Sub mnuDataDelete_Click()
Dim strMsg As String
'Verify the deletion.
strMsg = "Are you sure you want to delete " _
& IIf(txtProductName.Text <> "", txtProductName.Text, _
"this record") & "?"
If MsgBox(strMsg, vbQuestion + vbYesNo + vbDefaultButton2) = vbYes Then
' We really want to delete
datProducts.Recordset.Delete
' Make a valid record the current record and update the display.
datProducts.Recordset.MoveNext
' If we deleted the last record, move to the new last record
' because the current record pointer is not defined after
' deleting the last record, even though EOF is defined.
If datProducts.Recordset.EOF Then datProducts.Recordset.MoveLast
End If
End Sub
Private Sub mnuDataSave_Click()
' Invoke the update method to copy control contents to
' recordset fields and update the underlying table
datProducts.Recordset.Update
If datProducts.Recordset.EditMode <> dbEditAdd Then
' If we added move to the new record
datProducts.Recordset.MoveLast
End If
End Sub
Private Sub mnuEditUndo_Click()
' Undo all pending changes from form by copy recordset values
' to form controls
datProducts.UpdateControls
If datProducts.Recordset.EditMode = dbEditAdd Then
' Disable the menu save and cancel the update
datProducts.Recordset.CancelUpdate
mnuDataSave.Enabled = False
End If
End Sub
Private Sub mnuFileExit_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -