CSV文件未完全保存在表VBA中 [英] csv file is not saved completly in table vba

查看:127
本文介绍了CSV文件未完全保存在表VBA中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将这样的csv文件保存在表格中:

I tried to save such a csv file in a table:

XValue, YValue, Wert, Name, FzgID
, ,  "CARB (Evap Denom)",  DIUMPR_CldStrtDenCldStrtTyp_C, 238
, , 800.0000000000000000,  DIUMPR_ctGen.l500MD_C, 238
, , 10000.0000000000000000,  DIUMPR_ctGen.l500MDInc_C, 238
, , 600.0000000000000000,  DIUMPR_ctGen.nIgnMin_C, 238
, , 740.0000000000000000,  DIUMPR_ctGen.pEnvMin_C, 238
, , 5.0048828125000000,  DIUMPR_ctGen.rAPPMax_C, 238

我正在使用以下代码:

DoCmd.TransferText acImportDelim, , "tb_DCM_Daten", Filename, True

我的问题是,对于csv文件中的第一行.它不会在表的Wert字段中保存CARB (Evap Denom)".其他行将毫无问题地保存.

My problem is, for the first row in csv file. It doesnt save CARB (Evap Denom)" in Wert field in the table. other rows are saved without any problem.

如果我的cvs文件只有这样一行:

If I have a cvs file with only one row like this:

     XValue, YValue, Wert, Name, FzgID
    , ,  "CARB (Evap Denom)",  DIUMPR_CldStrtDenCldStrtTyp_C, 238

此行也将与"CARB (Evap Denom)"

有人可以告诉我这次事件的原因吗?

could someone say me the cause of this event?

推荐答案

您已经省略了TransferText方法的第二个参数.该参数是 SpecificationName ,它是一个Import Specification的名称,它告诉Access该特定导入应该具有哪些字段名称和类型.

You have omitted the second argument to the TransferText method. That argument is the SpecificationName, which is the name of an Import Specification that tells Access what the field names and types are supposed to be for that particular import.

在没有导入规范的情况下,Access将查看CSV文件的前几行,并猜测"字段的类型.在您的情况下-除了第一行数据外,[Wert]看起来像一个数字字段,这就是Access创建的内容.由于不适合Number (Double)字段,因此不会导入第一条数据行中的值.

Without an Import Specification, Access will look at the first few lines of the CSV file and "guess" at what the field types should be. In your case - except for the first line of data - [Wert] looks like a numeric field, so that is what Access creates. The value from the first data line does not get imported because it is not suitable for a Number (Double) field.

您至少有两个选择:

(1)您可以通过在Access中执行手动导入,单击高级..."按钮,调整字段类型并单击另存为..."按钮来创建导入规范. ..

(1) You can create an Import Specification by performing a manual import in Access, clicking the "Advanced..." button, tweaking the Field type(s), and clicking the "Save As..." button ...

...然后将Import Specification的名称作为TransferText调用的第二个参数:

... then including the name of the Import Specification as the second argument to your TransferText call:

DoCmd.TransferText acImportDelim, "DCM Import Specification", "tb_DCM_Daten", Filename, True

...或...

(2)您可以先创建表(具有适当的字段名称和类型),然后将CSV文件导入到现有表中.

(2) You could create the table (with the appropriate field names and types) first, and then import the CSV file into the existing table.

这篇关于CSV文件未完全保存在表VBA中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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