简体   繁体   English

Access 2010或SQL Server 2008导出查询到自定义文本文件

[英]Access 2010 or SQL Server 2008 Export Query to Custom Text File

I am looking for a way to output records to a custom text file. 我正在寻找一种将记录输出到自定义文本文件的方法。 The key is the text file has two parts: 1. Command Script 2. Data Records The purpose is to output the file to a Watch folder where a Label Software will open the file process the Command Script and print the data records on labels. 关键是文本文件包含两个部分:1.命令脚本2.数据记录目的是将文件输出到Watch文件夹,标签软件将在其中通过命令脚本打开文件并在标签上打印数据记录。 I am using an Access 2010 Front-end and SQL Server 2008 backend. 我正在使用Access 2010前端和SQL Server 2008后端。 The text file is formated with the Script commands on lines 1 & 2 and the data begins on line 3. Below is an example of the text file: 文本文件在第1行和第2行使用脚本命令进行格式化,数据从第3行开始。以下是该文本文件的示例:

%BTW% /AF="C:\\ShippingLabelName.btw" /D="%Trigger File Name%" /PRN="LabelPrinterName" /R=3 /P /DD %END% "PackSlipNo","ShipLotNo","Qty","CustRev","CustPartNo","ShipDate","CustPO","Descrip","PartNo","SupplierNum","ID","MyQty","MyPartsPer","Dock","City","UserDefined1","UserDefined2","UserDefined3","UserDefined4","SerialNum" "99007865",20120097,24402,"NONE","440510404",6/18/2012 0:00:00,"0203109703","PINTLE","33949","9090551",9420,5,1000,"JRZ 2","SANTA TERESA",,,,,"150535" %BTW%/AF="C:\\ShippingLabelName.btw“ / D =”%Trigger文件名%“ / PRN =” LabelPrinterName“ / R = 3 / P / DD%END%” PackSlipNo“,” ShipLotNo“,” Qty”,“ CustRev”,“ CustPartNo”,“ ShipDate”,“ CustPO”,“ Descrip”,“ PartNo”,“ SupplierNum”,“ ID”,“ MyQty”,“ MyPartsPer”,“ Dock”,“ City” ,“ UserDefined1”,“ UserDefined2”,“ UserDefined3”,“ UserDefined4”,“ SerialNum”“ 99007865”,20120097、24402,“ NONE”,“ 440510404”,6/18/2012 0:00:00,“ 0203109703” ,“ PINTLE”,“ 33949”,“ 9090551”,9420、5、1000,“ JRZ 2”,“ SANTA TERESA”,“,”,“ 150535”

您可以使用VBA( DoCmd.TransferTextFileSystemObject )单独输出文件,也可以在VBA中使用DOS复制命令来连接两个文件( http://wiki.lessthandot.com/index.php/Combine_Two_Files_(Concatenate ) )

Assuming this isn't a one-time shot, the way I handle this kind of requirement is with the age-old open and print commands used to create precisely-customized text output files. 假设这不是一次性的,我处理这种要求的方法是使用用于创建精确定制的文本输出文件的古老的打开和打印命令。 Here's a little sample code. 这是一些示例代码。 This sample was pipe-delimited, but this method will allow you to output anything you want. 此示例是用管道分隔的,但是此方法将允许您输出所需的任何内容。

Open vpath For Output Lock Write As #1
Print #1, vmemo & "|" & Trim(rs!Memo) & "|" & Format(rs!txndate, "mm/dd/yyyy") & "|" & rs!RefNumber & "|" & "Paid" & "|" & Format(rs!AppliedToTxnAmount, "#,##0.00")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM