我正在尝试在 MSACCESS 中编写一个小型的、固定的应用程序(希望能编译成可执行文件),以允许用户选择任何“*.accdb”文件,然后将所选数据库中的所有表导出到 .CSV 文件。
请注意:此代码可以在某个数据库中使用,但我正在寻找一个工具来打开另一个数据库并从那里导出。
使用以下代码,我收到错误:3011 - Microsoft Access 数据库引擎找不到对象“FK Data Extract”。确保该对象存在并且其名称和路径名称拼写正确。如果“FK Data Extract”不是本地对象,请检查您的网络连接或联系服务器管理员。
感谢您的任何想法。
史蒂夫
Option Compare Database
Option Explicit
Private Sub Toggle12_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim f As Office.FileDialog
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
' Show the dialog. If the method returns True, the user picked at least one file.
' If the method returns False, the user clicked Cancel.
If f.Show Then
'MsgBox f.SelectedItems.Count & " file(s) were chosen."
MsgBox f.SelectedItems(1)
End If
Call OpenDb(f.SelectedItems(1))
End Sub
Public Function OpenDb(sDb As String)
On Error GoTo Err_ExportDatabaseObjects
Dim oAccess As Access.Application
Dim BigIn_fn As Variant
Set oAccess = CreateObject("Access.Application") 'Create a new Access instance
With oAccess
.OpenCurrentDatabase sDb 'Open the specified db
.Visible = True 'Ensure it is visible to the end-user
.UserControl = True
Dim td As TableDef
Dim d As Document
Dim c As Container
Dim i As Integer
Dim sExportLocation As String
sExportLocation = "C:\users\steve\"
For Each td In .CurrentDb.TableDefs 'Tables
Debug.Print td.Name
If Left(td.Name, 4) <> "MSys" Then
DoCmd.TransferText acExportDelim, , td.Name, sExportLocation & "Table_" & td.Name & ".csv", True
End If
Next td
Set db = Nothing
Set c = Nothing
MsgBox "All database objects have been exported as a csv file to " & sExportLocation, vbInformation
Exit_ExportDatabaseObjects:
Exit Function
Err_ExportDatabaseObjects:
Debug.Print Err.Number & " - " & Err.Description
MsgBox Err.Number & " - " & Err.Description
Resume Exit_ExportDatabaseObjects
End With
Exit Function
End Function
Error as above: 3011 - The Microsoft Access database engine could not find the object 'FK Data Extract'. Make sure the object exists and that you spell its name and the path name correctly. If 'FK Data Extract' is not a local object, check your network connection or contact the server administrator.
将 End With 和 Exit Function 移至 Exit_ 标签之前。