Public Function importFiles(byVal ifDirectory as String)
Dim strFile as String, rstImports as Recordset
[COLOR="Blue"]' Open a recordset based on the table tblImportedFiles[/COLOR]
Set rstImports = CurrentDb.OpenRecordset("tblImportedFiles", dbOpenDynaSet)
With rstImports
[COLOR="blue"]' Make sure ifDirectory ends with a "\"[/COLOR]
If Right(ifDirectory, 1) <> "\" Then ifDirectory = ifDirectory & "\"
[COLOR="blue"]' Get first file[/COLOR]
strFile = Dir(ifDirectory & "*.*", vbNormal)
Do
[COLOR="blue"]' If file is not found exit loop[/COLOR]
If Len(strFile & vbNullString) = 0 Then Exit Do
[COLOR="blue"]' If file ends in "." then skip it[/COLOR]
If Right(strFile, 1) = "." Then Goto nextFile
[COLOR="blue"]' If file does not end in ".txt" then skip it[/COLOR]
if Right(strFile, 4) <> ".txt" Then Goto nextFile
[COLOR="blue"]' Look for an existing entry of strFile in field importedFileName[/COLOR]
.FindFirst ("importedFileName = '" & strFile & "'")
If .NoMatch Then
[COLOR="blue"]' If an entry is not found then do import routines
' Import file code here
' ...[/COLOR]
[COLOR="blue"]' Once import is complete add a new record to table tblImportedFiles[/COLOR]
.AddNew
!importedFileName = strFile
.Update
Else
[COLOR="blue"]' If an entry is found then do file skipping routines
' Skip file code here[/COLOR]
Endif
nextFile:
[COLOR="blue"]' Get next file[/COLOR]
strFile = Dir
Loop
End With
[COLOR="blue"]' Close and clean up[/COLOR]
rstImports.Close
Set rstImports = Nothing
End Function