MS Access设置忽略日期转换错误

问题描述:

Access DB导入固定宽度的文本文件;一列主要是日期。
当日期不可用时,文件的创建者实际使用字符串Null
Access将表中的行与该字段实际为空。

An Access DB imports a fixed width text file; one column is mostly dates. When the date is not available, the file's creator actually uses the string "Null" Access puts the row in the table with that field actually null.

但是,当文件开始使用不同的字段宽度时,我复制了DB,调整了输入规范中的起始/宽度值,并导入。现在,所有有空值的行都会记录(表)_import_errors作为将文本转换为日期的错误。

But, when the files started coming with different field widths, I copied the DB, tweaked the starting/width values in the input spec, and imported. NOW, all the rows with null get logging in (table)_import_errors as an error converting text to date.

我发现没有设置(不是我更改任何)到解释一下。一个区别是,尽管这两个数据库都是Access 2000格式,但原始文件仍然在一台仍然具有Access 2000的机器上,而新的数据库正在由Access 2003处理。

I have found no setting (not that I changed any) to explain it. One difference is that although both DBs are in Access 2000 format, the original is on a machine that still has Access 2000, while the new one is being handled by Access 2003.

Access版本中的行为是否改变?预处理文件是唯一的解决方案?

Is that a behavior change in the Access version? Is pre-processing the file the only solution?

谢谢David。这就是我所做的(除了Excel部分),如果它没有固定。我发布,但显然有人不喜欢公众承认Access有错误。

Thanks, David. That's what I would have done (except for the Excel part) if it had not fixed itself. I posted that, but apparently someone didn't like the public admission that Access has bugs.

唯一改变的是固定宽度纯文本输入中的两个其他列较宽。然而访问决定丢弃整行,而不是仅连续三次尝试的日期字段。第四次,它仍然将其报告为错误,但导入了该行的其余部分。

The only thing that changed was that two other columns in the fixed width plain text input was wider. Yet Access "decided" to discard the whole row instead of just the date field for three consecutive attempts. The fourth time, it still reported it as an error but imported the rest of the row.

所以,当Access不正当行为没有好的理由时,再试一次或两次,然后尝试从文本中明确地编码转换。

So, when Access misbehaves for no good reason, try again a time or two, then try explicitly coding the conversion from text.

两种可能性:


  1. 使用将日期字段导入文本字段的缓冲区或缓冲表。然后,您可以将其处理为最终目标字段中的相应值。

  1. Use a buffer field or buffer table that imports the date field into a text field. Then you can process that into the appropriate values in the final destination field.

使用SQL导入而不是DoCmd.TransferText。在这种情况下你所做的是在FROM子句中使用一个连接字符串,所以你可以在SELECT中处理日期字段:

Use a SQL import instead of DoCmd.TransferText. What you do in that case is use a connect string in the FROM clause so you can then process the date field in your SELECT:



  SELECT Sheet1.FirstField, Replace(Sheet2.DateField, "NULL", Null) As DateField 
  FROM Sheet1 IN 'C:\Import\Spreadsheet.xls'[Excel 5.0;HDR=YES;IMEX=1;];

将其转换为INSERT查询,您是黄金。

Convert that into an INSERT query and you're golden.