A family of Microsoft relational database management systems designed for ease of use.
One option would be to clear the table at the beginning of the code:
CurrentDb.Execute "DELETE \* FROM MyTable", dbFailOnError
where MyTable is the name of the table.
Another option is to check in the code:
Public Sub listFiles(startFolder As String, Optional recurse As Boolean = True)
Dim fso, folder, file, subfolder
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
If LenB(startFolder) = 0 Then Exit Sub
On Error GoTo ErrorHappened
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("MyTable", dbOpenDynaset)
If Right(startFolder, 1) <> "\" Then startFolder = startFolder & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(startFolder)
For Each file In folder.Files
If fso.GetExtensionName(file.Path) <> "bak" And fso.GetExtensionName(file.Path) <> "ps1" Then
If DCount("\*", "MyTable", "FilePath='" & file.Path & "' AND FileName='" & file.Name & "'") = 0 Then
rst.AddNew
rst!FileName = file.Name
rst!FilePath = file.Path
rst!DateLastModified = file.DateLastModified
rst!DateCreated = file.DateCreated
rst.Update
End If
End If
Next file
If recurse Then
For Each subfolder In folder.SubFolders
listFiles subfolder.Path, recurse
Next subfolder
End If
ExitNow:
On Error Resume Next
rst.Close
Set rst = Nothing
Set dbs = Nothing
Set fso = Nothing
Set folder = Nothing
Set file = Nothing
Set subfolder = Nothing
Exit Sub
ErrorHappened:
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
Resume ExitNow
End Sub