TransferText Error - "The Microsoft Access database engine could not find the..."
I'm having an issue with the following code. I've attempted to build in the ability to select a zip file for import. The code references a function that successfully unzips the folder and loops over each subsequent file. My issue is that on the import piece, I get the following error: "The Microsoft Access database engine could not find the object '20130411012402_BKCHKY_Unusual_Lo.tsv.txt'. Make sure...".
I can import the files themselves using the same module once they are extracted but Access is having an issue with doing this all in one go.
I'm having an issue with the following code. I've attempted to build in the ability to select a zip file for import. The code references a function that successfully unzips the folder and loops over each subsequent file. My issue is that on the import piece, I get the following error: "The Microsoft Access database engine could not find the object '20130411012402_BKCHKY_Unusual_Lo.tsv.txt'. Make sure...".
I can import the files themselves using the same module once they are extracted but Access is having an issue with doing this all in one go.
Code:
If f.SelectedItems.Count > 0 Then
importStart = Now()
For Each file In f.SelectedItems
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.getfile(file)
intExtPosition = InStr(objFile.Name, ".")
If intExtPosition > 0 Then
If Right(objFile.Name, Len(objFile.Name) - intExtPosition) = "txt" Then
strFileCopy = objFile.Name
GoTo textFile
ElseIf Right(objFile.Name, Len(objFile.Name) - intExtPosition) = "zip" Then
parentFolder = objFileSystem.GetParentFolderName(objFile)
Call UnZip(parentFolder, objFile)
Set oApp = CreateObject("Shell.Application")
parentFolder = objFileSystem.GetParentFolderName(objFile)
For Each fileNameInZip In oApp.Namespace(objFile).Items
Set objFile = objFileSystem.getfile(parentFolder & "\" & fileNameInZip)
strFileCopy = objFile & ".txt"
objFile.Copy strFileCopy, True
With DoCmd
.SetWarnings False
.TransferText acImportDelim, "UnusualLoginImport", "Unusual Logins", strFileCopy, True
.SetWarnings True
End With
If strFileCopy <> objFile.Name Then Kill strFileCopy
Name objFile.Name As objFile.Name & ".imported"
Next
GoTo zipFile
End If
strFileCopy = Left(objFile.Name, intExtPosition - 1) & ".txt"
Else
strFileCopy = objFile.Name & ".txt"
End If
objFile.Copy strFileCopy, True
textFile:
With DoCmd
.SetWarnings False
.TransferText acImportDelim, "UnusualLoginImport", "Unusual Logins", strFileCopy, True
.SetWarnings True
End With
If strFileCopy <> objFile.Name Then Kill strFileCopy
Name file As file & ".imported"
zipFile:
Next