Hi all just thought I'd share some code with you, in the hope that someone might find it useful. Will post each snippet seperately.
The first one copies files to be imported to a different folder (as the files I am importing are on a server, by copying them locally the import process should be quicker).
There is a table tcfgConfig that specifies the file locations and a module to retrieve the info from it.
Much of the code here I have found and adapted to my needs on the forum, so many thanks to contributors.
Anyway hope someone finds it useful, comments for improvement welcome
The first one copies files to be imported to a different folder (as the files I am importing are on a server, by copying them locally the import process should be quicker).
There is a table tcfgConfig that specifies the file locations and a module to retrieve the info from it.
Much of the code here I have found and adapted to my needs on the forum, so many thanks to contributors.
Anyway hope someone finds it useful, comments for improvement welcome

Code:
Public Sub sFileToImportLocation(strFDir As String, strFType As String, bSFldrs As Boolean)
'==========
'
' Name:
' sFileToImportLocation
'
' Purpose:
' To copy the file(s) to be imported, to the import location.
'
' Parameters In:
' strFDir The directory to look for files to copy over.
' strFType The type of files to copy over.
' bSFldrs Whether to look in subfolders or not.
'
'==========
Dim dbFTimp As Database ' Database object.
Dim rstFTimp As Recordset ' Recordset object.
Dim objFS As Object ' FileSearch object.
Dim iFndCnt As Integer ' Integer for the number of files found.
Dim iFCnt As Integer ' Integer for the current file number found.
Dim strFTimp As String ' The name of the file to import, including the path.
Dim strFileName As String ' The name of the file to import, minus the path.
' Open the import status form.
DoCmd.OpenForm ("frmImportStatus")
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Time() & " Processing started"
Forms!frmImportStatus.htxtCPrk.SetFocus
' Create the database and recordset objects.
Set dbFTimp = CurrentDb()
Set rstFTimp = dbFTimp.OpenRecordset("tmpFilesToImport", dbOpenDynaset)
' Create the FileSearch object.
Set objFS = Application.FileSearch
With objFS
' Look for the files of type strFType, in strFDir.
.LookIn = strFDir
.FileName = "*" & strFType
.SearchSubFolders = bSFldrs
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Searching for files of type *" & strFType
Forms!frmImportStatus.htxtCPrk.SetFocus
' Run the file search.
' If there are files of the type strFType in strFDir then, check if they have been imported, if not import them.
If .Execute > 0 Then
' Get the number of files found.
iFndCnt = .FoundFiles.Count
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Found " & iFndCnt & " files of type *" & strFType
' Add the name of the file to import to tblFilesToImport, if not already imported.
For iFCnt = 1 To iFndCnt
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Processing file " & iFCnt & " of " & iFndCnt
' Get the name of the found file, including the path.
strFTimp = .FoundFiles(iFCnt)
' List files to ignore here.
If strFTimp = strApplicationPath & strSaveFromPath & "\Failed Attempts active.csv" Then GoTo Next_FTimp
If strFTimp = strApplicationPath & strSaveFromPath & "\Failed Attempts 2003-08-26(13-54-42).csv" Then GoTo Next_FTimp
' Set the file name for saving in the table, - 1 removes the \.
strFileName = Right(strFTimp, Len(strFTimp) - Len(strApplicationPath) - Len(strSaveFromPath) - 1)
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Checking if '" & strFileName & "' has already been imported"
' Check that the file has not yet been imported.
If fFileImported(strFTimp) = False Then
' Add the name of the file tmpFilesToImport.
' Goto the last record.
If Not rstFTimp.EOF Then rstFTimp.MoveLast
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Adding file name to tblFilesToImport"
' Add the new record - saves only the file name, not the path.
rstFTimp.AddNew
rstFTimp.Fields("strFileToImportName").Value = strFileName
rstFTimp.Update
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Copying the file '" & strFileName & "' to the import from location"
' Copy the file to import to the import location.
FileCopy strFTimp, strApplicationPath & strImportFromPath & "\" & strFileName
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Importing data from the file '" & strFileName & "'"
' Import the data from the CSV file just copied.
'
Else:
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " '" & strFileName & "' Already imported"
End If
Next_FTimp:
' Check the next file.
Next iFCnt
Else:
' Add a comment to the import status form so that the user knows something is happening.
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " No files to import"
End If
End With
' Clear and close recordset, database and other objects.
rstFTimp.Close
dbFTimp.Close
Set rstFTimp = Nothing
Set dbFTimp = Nothing
Set objFS = Nothing
' Add a comment to the caption of tstCodeTesting so that the user knows something is happening.
Forms!tstCodeTesting.Caption = "Processing Complete"
Forms!frmImportStatus.txtImportStatus.Value = Forms!frmImportStatus.txtImportStatus.Value & Chr(13) + Chr(10) & _
Time() & " Processing Complete"
End Sub
Last edited: