📄 form1.frm
字号:
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Begin VB.Form Form1
Caption = "将Excel数据传给Access数据库"
ClientHeight = 3765
ClientLeft = 60
ClientTop = 345
ClientWidth = 7050
LinkTopic = "Form1"
ScaleHeight = 3765
ScaleWidth = 7050
StartUpPosition = 1 '所有者中心
Begin VB.TextBox Text4
Height = 285
Left = 5865
TabIndex = 6
Text = "Text4"
Top = 555
Width = 1080
End
Begin VB.TextBox Text3
Height = 285
Left = 5865
TabIndex = 5
Text = "Text3"
Top = 135
Width = 1080
End
Begin VB.TextBox Text2
Height = 285
Left = 1245
TabIndex = 4
Top = 555
Width = 3525
End
Begin VB.TextBox Text1
Height = 285
Left = 1245
TabIndex = 3
Top = 135
Width = 3525
End
Begin VB.CommandButton Command2
Caption = "退出"
Height = 390
Left = 5400
TabIndex = 2
Top = 3345
Width = 1560
End
Begin MSDBGrid.DBGrid DBGrid1
Bindings = "Form1.frx":0000
Height = 2265
Left = 105
OleObjectBlob = "Form1.frx":0014
TabIndex = 1
Top = 990
Width = 6855
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "D:\VB精彩编程200例\第3章 数据库\(实例117)将Excel数据传给Access文件\123.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 345
Left = -45
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "ma"
Top = 2730
Visible = 0 'False
Width = 1410
End
Begin VB.CommandButton Command1
Caption = "导入excel"
Height = 390
Left = 3795
TabIndex = 0
Top = 3345
Width = 1560
End
Begin VB.Label Label4
Caption = "access文件:"
Height = 255
Left = 4860
TabIndex = 10
Top = 630
Width = 1095
End
Begin VB.Label Label3
Caption = "excel文件:"
Height = 255
Left = 4860
TabIndex = 9
Top = 180
Width = 1005
End
Begin VB.Label Label2
Caption = "access路径:"
Height = 255
Left = 195
TabIndex = 8
Top = 585
Width = 1095
End
Begin VB.Label Label1
Caption = "excel路径:"
Height = 255
Left = 195
TabIndex = 7
Top = 135
Width = 1005
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Text1.Text = App.Path & "\123.xls"
Text2.Text = App.Path & "\123.mdb"
Text3.Text = "sheet1"
Text4.Text = "sheet1"
Data1.DatabaseName = App.Path & "\123.mdb"
End Sub
Private Sub Command1_Click()
Dim db As Database
Dim sheet As String, excelpath As String, AccessPath As String, AccessTable As String
AccessPath = Text2.Text '数据库路径
excelpath = Text1.Text '电子表格路经
AccessTable = Text4.Text '数据库内表格
sheet = Text3.Text '电子表格内工作表
Set db = OpenDatabase(excelpath, True, False, "Excel 5.0") '打开电子表格文件
SQL = ("Select * into [;database=" & AccessPath & "]." & AccessTable & " FROM [" & sheet & "$]")
db.Execute (SQL) '将电子表格导入数据库
Data1.RecordSource = "sheet1"
Data1.Refresh
DBGrid1.Refresh '显示电子表格导入到数据库的数据
End Sub
Private Sub Command2_Click()
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -