I have a database that imports data weekly from CSV files saved by field staff to a particular folder (they pull data stored in remote sensors). Import works great *unless* they put a period anywhere in the file name. For example, "example 10-29-2012.csv" works fine, but "example 10.29.2012" throws an error. Since staff turns over, I would rather fix the bug than enforce a naming convention.
The code finds the file just fine and stores the name correctly. The bug only comes at the TransferText command and gives the error that it can't find the named file.
Code below. Any ideas how to fix this error?
Thanks,
Tyler
The code finds the file just fine and stores the name correctly. The bug only comes at the TransferText command and gives the error that it can't find the named file.
Code below. Any ideas how to fix this error?
Thanks,
Tyler
Code:
Public Function ImportFile()
Dim strFile As String
Dim strDir As String
Dim StrDirBkup As String
Dim TempName As String
Dim OldName As String
Dim NewName As String
Dim objFSO As Object
DoCmd.SetWarnings (False)
strDir = "(file path removed)"
StrDirBkup = "(file path removed)"
strFile = Dir(strDir & "*.csv")
Do While strFile <> ""
DoCmd.TransferText acImportDelim, "ImportSpec", "Import", strDir & strFile, False <----- ERROR HERE
DoCmd.OpenQuery "Import qry"
DoCmd.OpenQuery "Clear Import qry"
OldName = strDir & strFile
NewName = StrDirBkup & strFile
retval = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
retval = objFSO.CopyFile(OldName, NewName, True)
Set objFSO = Nothing
Kill strDir & strFile
strFile = Dir(strDir & "*.csv")
Loop
DoCmd.OpenQuery "Update Locations"
DoCmd.OpenQuery "Import Last - clear New flags"
If MsgBox("Check for duplicates?", vbYesNo) = 6 Then
DoCmd.OpenQuery "Duplicates 2"
DoCmd.OpenQuery "Duplicates 3b - clear close reads"
DoCmd.OpenQuery "Duplicates 4b - updatable"
End If
DoCmd.OpenQuery "Available Data qry"
DoCmd.OpenTable "Available Data"
DoCmd.OpenForm "Selection Form"
DoCmd.SetWarnings (True)
End Function