Handle TransferText Errors

我与影子孤独终老i 提交于 2019-11-30 09:07:21

问题


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

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

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

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.

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

Any idea ?


回答1:


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

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]

In VBA:

Dim db As Database
Set db = CurrentDB

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

References:
Errors Collection (DAO)
Error Object (DAO)
Schema.ini File (Text File Driver)



来源:https://stackoverflow.com/questions/14730093/handle-transfertext-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!