使用VBScript将Access表导出到带分隔符的txt文件

使用VBScript将Access表导出到带分隔符的txt文件,vbscript,ms-access-2007,Vbscript,Ms Access 2007,我需要用将我的表从DB Access 2007导出到带分隔符的txt文件 我的代码如下: Set accDB = CreateObject("Access.Application") accDB.visible = true accDB.automationsecurity = 1 accDB.OpenCurrentDatabase("D:\Users\db2015.mdb") accDB.DoCmd.Trans

我需要用
将我的表从DB Access 2007导出到带分隔符的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 
这里发生的是:

VBScript不知道
acExportDelim
,因此它被解释为未知变量,值为0

DoCmd.TransferText
的上下文中,0=
acImportDelim

因此,它尝试导入tb2015.txt,您会得到“未找到文件”错误

从Access对象目录复制
Const acExportDelim=2
,并将其添加到脚本中。并删除“;”SpecificationName参数

注意:
acOutputTable=0
,这就是为什么
DoCmd.OutputTo
会意外运行的原因


为避免此类错误,请添加到脚本的顶部,它强制执行变量声明。

您可以尝试,我非常怀疑“;”是规范的名称,请参阅“但我有错误”-什么错误?哪一行?对不起,我在第11行中有错误
accDB.DoCmd.TransferText acExportDelim,“tb2015”,“D:\Users\tb2015.txt”,False
错误是因为操作或方法需要主题对不起,我在第11行中有错误
accDB.DoCmd.TransferText acExportDelim,“tb2015”,“D:\Users\tb2015.txt”,False
错误是因为操作或方法需要参数–在编辑中解决。2谢谢您的帮助,请参阅第一个问题中的“我的编辑”,建议无效。