📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3795
ClientLeft = 60
ClientTop = 345
ClientWidth = 5970
LinkTopic = "Form1"
ScaleHeight = 3795
ScaleWidth = 5970
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "删除记录"
Height = 615
Left = 1080
TabIndex = 1
Top = 2040
Width = 3015
End
Begin VB.CommandButton Command1
Caption = "增加记录"
Height = 735
Left = 1080
TabIndex = 0
Top = 720
Width = 2895
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 db As DAO.Database
Dim rst As DAO.Recordset
'打开数据库
'根据实际设置数据库位置
On Error GoTo errhanle
Set db = DBEngine.OpenDatabase(App.Path + "\MySampleDB.mdb")
Set rst = db.OpenRecordset("SELECT * FROM 客户表", dbOpenDynaset)
'添加记录
rst.AddNew
'设置记录的字段值
rst!CustomerId = "MIKE"
rst!CompanyTitle = "MIKE NET CO"
rst!LinkMan = "Mike Henry"
rst!Address = "10 xitucheng Street"
rst!PostCode = "100876"
rst!Phone = " (010)00000000"
rst!Fax = " (010) 11111111"
'保存修改
rst.Update
MsgBox "保存成功!"
rst.Bookmark = rst.LastModified
Debug.Print rst!CustomerId
'关闭数据库
rst.Close
Exit Sub
errhanle:
MsgBox "数据库中已经存在该记录,请按删除!"
End Sub
Private Sub Command2_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
'根据实际设置数据库位置
Set db = DBEngine.OpenDatabase(App.Path + "/MySampleDB.mdb")
'打开数据记录集,这里使用SQL语言打开
Set rs = db.OpenRecordset("SELECT * FROM 客户表 WHERE CustomerID = 'MIKE'")
If rs.RecordCount > 0 Then
rs.Delete
MsgBox "删除成功!"
Else
MsgBox "不存在记录!"
End If
rs.Close
db.Close
End Sub
Private Sub Form_Load()
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -