我需要從DB Access 2007導出我的表以使用VBScript與;
分隔txt文件。使用VBScript導出訪問表以分隔txt文件
我下面的代碼:
Set accDB = CreateObject("Access.Application")
accDB.visible = true
accDB.automationsecurity = 1
accDB.OpenCurrentDatabase("D:\Users\db2015.mdb")
accDB.DoCmd.TransferText acExportDelim, ";", "tb2015", "D:\Users\tb2015.txt", False
accDB.CloseCurrentDatabase
accDB.Quit
Set accDB = Nothing
但我有錯誤:tb2015.txt找不到
我試圖加在我的代碼如下:
accDB.DoCmd.OpenQuery "SelectQuery", acNormal, acEdit
accDB.DoCmd.OutputTo acOutputTable, "tb2015", "txt", "D:\Users\tb2015.txt"
在這種情況下,我不沒有錯誤,但tb2015.txt與|
而不是;
請幫幫我。
預先感謝您。
編輯#1
這是新的代碼,但我有錯誤:
Set accDB = CreateObject("Access.Application")
accDB.visible = true
accDB.automationsecurity = 1
accDB.OpenCurrentDatabase("D:\Users\db2015.mdb")
Const acExportDelim = 2
accDB.DoCmd.TransferText acExportDelim, , "tb2015", "D:\Users\tb2015.txt", False
accDB.CloseCurrentDatabase
accDB.Quit
Set accDB = Nothing
編輯#2
解決的辦法是這樣的代碼:
Const acExportDelim = 2
Set accDB = CreateObject("Access.Application")
accDB.visible = true
accDB.automationsecurity = 1
accDB.OpenCurrentDatabase("D:\Users\db2015.mdb")
accDB.DoCmd.OpenQuery "myView", acNormal, acEdit
accDB.DoCmd.TransferText acExportDelim, "tb2015", "tb2015", "D:\Users\tb2015.txt"
accDB.CloseCurrentDatabase
accDB.Quit
Set accDB = Nothing
你可以嘗試http://stackoverflow.com/questions/13482242/create-comma-separated-file-csv-from-access-scheduled-daily-from-windows/13483597#13483597我非常懷疑,「; 「是您的規範的名稱,請參閱https://msdn.microsoft.com/en-us/library/bb214141(v=office.12).aspx – Fionnuala
*「但我有錯誤」* - 什麼錯誤?在哪一行? – Andre
對不起,我有第11行錯誤'accDB.DoCmd.TransferText acExportDelim,,「tb2015」,「D:\ Users \ tb2015.txt」,False錯誤是**爲行動或方法需要主題** –