【发布时间】:2016-02-26 15:17:51
【问题描述】:
我正在导入从 Excel 导出的 txt 文件,并以一般格式结束,即 42408 等。
将其导入 Access 时,将其作为导入没有问题。 (我将数据类型设置为日期等,它可以工作 -> 没有导入错误。)
但是,当我尝试使用以下代码多重导入时,除了我收到“类型转换错误”的日期之外,所有内容都会导入。
现在,我认为问题在于导入规范。 [查看图片]
有人知道导入规范的配置可以使它工作吗?
Database file here (also I have included the import txt file)
Sub import_multiple_files()
On Error GoTo bImportFiles_Click_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "s:\downloads\import_files\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "txt" Then
DoCmd.TransferText acImportDelim, "TextImportSpecs", "tblImportedFiles", strFolderPath & objF1.Name, False
Name strFolderPath & objF1.Name As "s:\downloads\Archived Files\" & objF1.Name 'Move the files to the archive folder
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
bImportFiles_Click_Exit:
Exit Sub
bImportFiles_Click_Err:
MsgBox Err.Number & " " & Err.Description
Resume bImportFiles_Click_Exit
End Sub
【问题讨论】: