本文介绍了处理 TransferText 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Access-2007 应用程序,我使用 Visual Basic 从文本文件导出/导入表格.

I have an Access-2007 application, I use Visual Basic to export/import tables from text file.

DoCmd.TransferText acExportDelim, "MySpec", "Table1", "c:	able1.txt", True

DoCmd.TransferText acImportDelim, "MypSpec", "Table1", "c:	able1.txt", True

我想捕获此方法可能引发的所有错误.我想要这个方法的错误号列表,我在 MSDN 上搜索过,但没有找到任何东西.

I want to trap all errors that this method can raise. I want to have the list of this method's error numbers, I searched on MSDN but I didn't find any thing.

此外,如果导入失败,我还想阻止访问创建 ImportErrors 表.

Also I want to prevent access from creating ImportErrors table if the import fails.

有什么想法吗?

推荐答案

如果要对数据进行预测试,可以使用 SQL.

You can use SQL if you want to pre-test the data.

使用 schema.ini 文件并直接导入到 MS Access.schema.ini 文件相当于规范.

Use a schema.ini file and a straight import to MS Access. A schema.ini file is comparable to a specification.

[imp.txt]
ColNameHeader=False
Format=FixedLength
Col1=ID  Char Width 8
Col2=AName  Char Width 10
Col3=Mark Char Width 2

SQL

SELECT * INTO Imp FROM [Text;DATABASE=Z:docs].[imp.txt]

在 VBA 中:

Dim db As Database
Set db = CurrentDB

sSQL = "SELECT * INTO Imp FROM [Text;DATABASE=Z:docs].[imp.txt]"
db.Execute sSQL, dbFailOnError

参考文献:
错误集合 (DAO)
错误对象 (DAO)
Schema.ini 文件(文本文件驱动程序))

这篇关于处理 TransferText 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 07:45