📄 form1.frm
字号:
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Begin VB.Form Form1
Caption = "将Access导出成多种数据格式"
ClientHeight = 3780
ClientLeft = 60
ClientTop = 345
ClientWidth = 5235
LinkTopic = "Form1"
ScaleHeight = 3780
ScaleWidth = 5235
StartUpPosition = 1 '所有者中心
Begin MSDBGrid.DBGrid DBGrid1
Bindings = "form1.frx":0000
Height = 2745
Left = 105
OleObjectBlob = "form1.frx":0014
TabIndex = 5
Top = 120
Width = 4980
End
Begin VB.CommandButton Command5
Caption = "退出"
Height = 450
Left = 4095
TabIndex = 4
Top = 3255
Width = 1000
End
Begin VB.CommandButton Command4
Caption = "导出为Excel文件"
Height = 450
Left = 90
TabIndex = 3
Top = 3255
Width = 1000
End
Begin VB.CommandButton Command3
Caption = "导出为HTML文件"
Height = 450
Left = 1095
TabIndex = 2
Top = 3255
Width = 1000
End
Begin VB.CommandButton Command2
Caption = "导出为TXT文件"
Height = 450
Left = 2100
TabIndex = 1
Top = 3255
Width = 1000
End
Begin VB.CommandButton Command1
Caption = "导出为DBase文件"
Height = 450
Left = 3090
TabIndex = 0
Top = 3255
Width = 1000
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "E:\编程技巧\path.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 345
Left = 1080
Options = 0
ReadOnly = 0 'False
RecordsetType = 0 'Table
RecordSource = "path"
Top = 0
Visible = 0 'False
Width = 1155
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "导出的文件被保存在C盘根目录下"
ForeColor = &H000000FF&
Height = 285
Left = 135
TabIndex = 6
Top = 2940
Width = 4785
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim db As Database
Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\path.mdb" '设置数据库路径
Set db = Workspaces(0).OpenDatabase(App.Path & "\path.mdb") '打开数据库
End Sub
Private Sub Form_Activate() '设置dbgrid控件列宽
DBGrid1.Columns(0).Width = 2200
DBGrid1.Columns(1).Width = 0
DBGrid1.Columns(2).Width = 0
DBGrid1.Columns(3).Width = 3800
End Sub
Private Sub Command1_Click()
On Error Resume Next
Command1.Enabled = False
db.Execute "SELECT * INTO [dBase III;DATABASE=C:\].[path.DBF] FROM [path]" '导出dbase文件格式
Command1.Enabled = True
End Sub
Private Sub Command2_Click()
On Error Resume Next
Command2.Enabled = False
db.Execute "SELECT * INTO [Text;DATABASE=C:\].[path.TXT] FROM [path]" '导出txt文件格式
Command2.Enabled = True
End Sub
Private Sub Command3_Click()
On Error Resume Next
Command1.Enabled = False
db.Execute "SELECT * INTO [HTML Export;DATABASE=C:\].[path.HTM] FROM [path]" '导出html文件格式
Command1.Enabled = True
End Sub
Private Sub Command4_Click()
On Error Resume Next
Command1.Enabled = False
db.Execute "SELECT * INTO [Excel 8.0;DATABASE=C:\path.XLS].[path] FROM [path]" '导出Excel文件格式
Command1.Enabled = True
End Sub
Private Sub Command5_Click()
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -