[英]Error 3011 VBA exporting all tables to txt in access
我是 Visual Basic 的新手,我正在嘗試將所有表以 ms 訪問權限導出到文本文件。
我有這個代碼
Function save2txt() As String
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On Error GoTo errHandler
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb
For Each tdf In db.TableDefs
' ignore system and temporary tables
If Not (tdf.Name Like "MSys*" Or tdf.Name Like "~*") Then
Debug.Print tdf.Name
DoCmd.TransferText transfertype:=acExportDelim, specificationname:="ExportSpec", tablename:=tdf.Name, FileName:=Application.CurrentProject.Path & "\" & tdf.Name & ".txt", hasfieldnames:=True
End If
Next
Set tdf = Nothing
Set db = Nothing
errHandler:
Debug.Print Err.Number & " " & Err.Description
End Function
前 3 個表被導出到 .txt,然后我收到錯誤 3011。當我嘗試手動導出時,會彈出一個窗口,提示該字段不存在。 我正在使用使用向導保存的規范進行導出。
這是出現在 MSysIMEXSpec 中的內容:
DateDelim: /
DateFourDigitYear: -1
DateLeadingZeros: 0
DateOrder: 0
DecimalPoint: .
FieldSeparator: ,
FileType: 1252
SpecId: 2
SpecName: ExportSpec
SpecType: 1
StartRow: 0
TextDelim:
TimeDelim: :
我遇到了同樣的問題,我發現其中一個表的字段名稱與規范中定義的字段名稱不同。 您將不得不為具有其他列名中不存在的列名的表創建不同的規范。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.