vbscript将访问查询导出到制表符分隔的文件不起作用 [英] vbscript to export an access query to a tab delimited file not working

查看:71
本文介绍了vbscript将访问查询导出到制表符分隔的文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

db = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\baywotch.db5"
TextExportFile = "C:\Dokumente und Einstellungen\hom\Anwendungsdaten\BayWotch4\Neuer Ordner\Exp.txt"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open _
   "Provider = Microsoft.Jet.OLEDB.4.0; " & _
   "Data Source =" & db

strSQL = "SELECT * FROM tblAuction1"

rs.Open strSQL, cn, 3, 3

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.CreateTextFile(TextExportFile, True)

a = rs.GetString

f.WriteLine a

f.Close

用于连接到Access数据库并生成制表符分隔的文本文件. tblAuction1是数据库中的一个查询,并且确实存在并且绝不会以任何方式遗漏,但是我收到一个错误,指出找不到或不存在该错误.当我将其更改为表名tblAuction时,出现错误,指出f.WriteLine a被错误地调用.

Which is meant to connect to an access database and produce a tab delimited text file. tblAuction1 is a query in the database, and definitly exists and is not misspelt in any way, but I get an error that it cannot be found or does not exist. When I change it to tblAuction which is the name of the table, I get an error stating f.WriteLine a has been called incorrectly.

edit:我现在仅对f.writeline a遇到问题,说提供了不正确的参数.我不再对tblAuction1有问题

edit: I now only get a problem with f.writeline a, saying an incorrect argument has been supplied. I no longer have a problem with tblAuction1

用于查询的sql代码:

edit: the sql code used for my query:

SELECT tblAuction.article_no, tblAuction.article_name, tblAuction.subtitle, tblAuction.current_bid, tblAuction.start_price, tblAuction.bid_count, tblAuction.quant_total, tblAuction.quant_sold, tblAuction.start, tblAuction.ends, tblAuction.origin_end, tblUser.user_name, tblAuction.best_bidder_id, tblAuction.finished, tblAuction.watch, tblAuction.buyitnow_price, tblAuction.pic_url, tblAuction.private_auction, tblAuction.auction_type, tblAuction.insert_date, tblAuction.update_date, tblAuction.cat_1_id, tblAuction.cat_2_id, tblAuction.article_desc, tblAuction.countrycode, tblAuction.location, tblAuction.condition, tblAuction.revised, tblAuction.paypal_accept, tblAuction.pre_terminated, tblAuction.shipping_to, tblAuction.fee_insertion, tblAuction.fee_final, tblAuction.fee_listing, tblAuction.pic_xxl, tblAuction.pic_diashow, tblAuction.pic_count, tblAuction.item_site_id
FROM tblUser INNER JOIN tblAuction ON tblUser.id = tblAuction.seller_id;

推荐答案

我试图在多个数据库和计算机上重现此错误,但是我无法使您的代码失败.

I have tried to reproduce this on several databases and machines, I can't get your code to fail.

叶子:

  • 损坏的数据库,能否请您进行修复并重试?
  • 您的数据库中引发查询的字段,我尝试了几种可能性,但找不到任何阻碍您代码的东西.要排除其他内容,您可以尝试创建一个新表并查看您的代码是否可以在该表上工作.
  • 您的dll出了点问题,您可以在另一台机器上尝试它吗?

答案(要了解我们如何得出答案,请参阅评论)

Answer (to see how we came to the answer see the comments)

您的数据库中有一些unicode字符不被writeline接受,因为您将文本文件创建为ASCI.在这种情况下,这些字符专门用于♥♥♥

There are unicode characters in your database that writeline does not accept because you created the textfile as ASCI.The characters in this case specifically where ♥♥♥

要使其正常工作:

Set f = fs.CreateTextFile(TextExportFile, True, True)

P.S.

早些时候,使用transfertext宏此处回答了此问题 正如 Remou 指出的那样,这似乎是一种更清洁的解决方案.要使其与非默认定界符一起使用,会有些麻烦.首先,右键单击并选择导出,开始导出要导出的查询.在以下对话框中,指定规格并保存.创建宏时,请选择刚刚保存的规范.

This question was answered earlier using the transfertext macro here As Remou points out this looks like a cleaner solution. To make it work with non-default delimiters is a bit of a pain. First start exporting the query you like to export by right clicking and choose export. In the following dialogs specify the specifications and save these. When creating the macro select the specifications you just saved.

这篇关于vbscript将访问查询导出到制表符分隔的文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆