turks67 via AccessMonster.com said:
I have a table with files I have already imported. The problem is that the
same file get imported with the new files. how can I move the old files
only?
As you go through the list of files in the folder, look each one up in the
table to see if it has already been imported, and only import it if it
hasn't. Here's a very rough example of the sort of logic I mean:
'------ start of example code ------
Dim strFolderPath As String
Dim strFileName As String
Dim db As DAO.Database
Set db = CurrentDb
strFolder = "C:\Your Path\To\Your Folder\"
' Get first .txt file in folder.
strFileName = Dir(strFolder & "*.txt")
' Loop to process all .txt files.
Do Until Len(strFileName) = 0
' Have we already imported this one?
If IsNull(DLookup("FileName", "ImportedFiles", _
"FileName=" & Chr(34) & strFileName & Chr(34))) _
Then
' We haven't already imported it, so import this file.
strPathFile = strFolderPath & strFIleName
DoCmd.TransferText acImportDelim, strSpec, strTable, strPathFile
' Record this import in the ImportedFiles table.
db.Execute _
"INSERT INTO ImportedFiles (FileName, ImportDate) " & _
"VALUES(" & Chr(34) & strFileName & Chr(34) & _
", " & Format(Date(), "\#mm\/dd\/yyyy\#") & ")",
_
dbFailOnError
End If
' Get next .txt file.
strFileName = Dir()
Loop
Set db = Nothing
'------ end of example code ------