📄 frmadd.frm
字号:
VERSION 5.00
Begin VB.Form frmadd
BorderStyle = 1 'Fixed Single
Caption = "添加记录"
ClientHeight = 3780
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
ControlBox = 0 'False
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3780
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdexit
Caption = "退出"
BeginProperty Font
Name = "隶书"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3240
TabIndex = 12
Top = 3240
Width = 975
End
Begin VB.CommandButton cmdrep
Caption = "重填"
BeginProperty Font
Name = "隶书"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1800
TabIndex = 11
Top = 3240
Width = 975
End
Begin VB.CommandButton cmdok
Caption = "添加"
Default = -1 'True
BeginProperty Font
Name = "隶书"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 480
TabIndex = 10
Top = 3240
Width = 975
End
Begin VB.TextBox Txtpri
BeginProperty DataFormat
Type = 1
Format = """¥""#,##0.00"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 2
EndProperty
Height = 270
Left = 1680
TabIndex = 9
Top = 2660
Width = 1215
End
Begin VB.TextBox txttype
Height = 270
Left = 1680
TabIndex = 8
Top = 2060
Width = 1215
End
Begin VB.TextBox txtpub
Height = 270
Left = 1680
TabIndex = 7
Top = 1460
Width = 2295
End
Begin VB.TextBox txtname
Height = 270
Left = 1680
TabIndex = 3
Top = 860
Width = 2535
End
Begin VB.TextBox Txtid
Height = 270
Left = 1680
TabIndex = 1
Top = 260
Width = 1215
End
Begin VB.Label lblpri
Caption = "价格"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 960
TabIndex = 6
Top = 2685
Width = 495
End
Begin VB.Label lbltype
Caption = "类型"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 960
TabIndex = 5
Top = 2100
Width = 495
End
Begin VB.Label lblpub
Caption = "出版社"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 960
TabIndex = 4
Top = 1500
Width = 855
End
Begin VB.Label lblname
Caption = "书名"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 960
TabIndex = 2
Top = 915
Width = 495
End
Begin VB.Label lblid
Caption = "ISBN"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 960
TabIndex = 0
Top = 315
Width = 495
End
End
Attribute VB_Name = "frmadd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'添加,编辑记录窗体
Option Explicit
Private Sub cmdexit_Click() '退出
Unload Me
End Sub
Private Sub Form_Load() '本窗体加载后让原窗体变为不可用
frmbook.Enabled = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) '退出前使原窗体变为可用
frmbook.Enabled = True
Unload Me
End Sub
Private Sub Txtid_KeyPress(keyascii As Integer) '判断ISBN的合法性
If keyascii >= Asc("0") And keyascii <= Asc("9") Or keyascii = 8 _
Or keyascii = 45 Or keyascii = 13 Then '仅允许输入数字,"-",删除键和回车
Exit Sub
Else
MsgBox "ISBN必须为数字或 “ - ” !", 48, Me.Caption
Txtid.SetFocus
End If
keyascii = 0 '使输入无效
End Sub
Private Sub txtpri_keypress(keyascii As Integer) '判断书名的合法性
If keyascii >= Asc("0") And keyascii <= Asc("9") Or keyascii = 8 _
Or keyascii = 46 Or keyascii = 13 Then '仅允许输入数字,小数点和删除键,回车键
Exit Sub
Else
MsgBox "价格输入不合法!必须为数字或小数点!", 48, Me.Caption
Txtpri.SetFocus
End If
keyascii = 0
End Sub
Private Sub cmdok_Click() '确定
Dim intkey As Integer '最终检查
With Txtid '检查ISBN是否输入
If Len(.Text) = 0 Then
MsgBox "ISBN必须录入!", 48, cmdok.Caption
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
Exit Sub
End If
End With
With txtname
If Len(.Text) = 0 Then '检查书名是否输入
MsgBox "书名必须录入!", 48, cmdok.Caption
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
Exit Sub
End If
End With
With txtpub
If Len(.Text) = 0 Then '检查出版社是否输入
MsgBox "出版社名不能为空!", 48, cmdok.Caption
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
Exit Sub
End If
End With
If cmdok.Caption = "添加" Then '根据本按键的标题来决定当前的操作是“添加”
intkey = MsgBox("是否添加此记录?", 33, Me.Caption) '还是修改
If intkey <> 1 Then
Txtid.SetFocus
Exit Sub
Else
myrecor.AddNew
End If
Else
intkey = MsgBox("是否保存对此记录的修改?", 33, Me.Caption)
If intkey <> 1 Then
Txtid.SetFocus
Exit Sub
End If
End If
dataupdate '将文本内容加入记录集的各字段中
myrecor.Update '实现源表的更新
End Sub
Public Sub dataupdate() '自定义SUB,用以将数据显示在DataGrid控件上
' myrecor.Requery
On Error GoTo lab:
With myrecor
.Fields(0) = Trim(Txtid.Text)
.Fields(1) = "《" & Trim(txtname.Text) & "》" '在书名上自动添加书名号并存入字段中
.Fields(2) = Trim(txtpub.Text)
.Fields(3) = Trim(txttype.Text)
.Fields(4) = Trim(Txtpri.Text)
End With
Exit Sub
lab:
MsgBox Err.Description
End Sub
Public Sub datalist() '自定义SUB,用以将DataGrid控件上的数据显示在文本框中
With myrecor
Txtid.Text = Trim(.Fields(0))
txtname.Text = Mid(Trim(.Fields(1)), 2, Len(Trim(.Fields(1))) - 2) '在书名上自动添加书名号并显示
txtpub.Text = Trim(.Fields(2))
txttype.Text = Trim(.Fields(3))
Txtpri.Text = Trim(.Fields(4))
End With
End Sub
Private Sub cmdrep_Click() '重填,清空所有文本框内容
Txtid.Text = ""
txtname.Text = ""
txtpub.Text = ""
txttype.Text = ""
Txtpri.Text = ""
Txtid.SetFocus
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -