Code:
Private Function FillDirToTable(colDirList As Collection _
, ByVal strFolder As String _
, strFileSpec As String _
, bIncludeSubfolders As Boolean)
Dim a
Dim strCamera As String
Dim dateMod As Date
Dim strDirectoryShort As String
Dim directory As String
Dim dateDD, dateMM, dateYY As Integer
'Build up a list of files, and then add add to this list, any additional folders
'On Error GoTo Err_Handler
Dim strErrMsg As String
Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant
Dim strSQL, strFilENP, strDateMod, strDateCreate, strSize As String
Dim strMsg As String
'Add the files to the folder.
strFunction = "FileList/FDTT"
strFolder = TrailingSlash(strFolder)
strTemp = Dir(strFolder & strFileSpec)
strDirectoryShort = GetRightFolder(strFolder)
Do While strTemp <> vbNullString
gCount = gCount + 1
SysCmd acSysCmdSetStatus, gCount
strFilENP = strFolder & strTemp
dateMod = ShowFileInfo(strFilENP, "M") 'get file mod date
strDateCreate = ShowFileInfo(strFilENP, "C") 'get file CREATE date
strSize = ShowFileInfo(strFilENP, "S") 'get fiel size
strTemp = Trim(strTemp)
dateDD = Day(dateMod)
dateMM = Month(dateMod)
dateYY = year(dateMod)
a = Split(strTemp, ".")
strCamera = a(0)
strSQL = "INSERT INTO tClips " _
& " (directoryShort, directory, filename, fileSize, dateMod, dateDD, dateMM, dateYY, camera) " _
& " VALUES ( """ & strDirectoryShort & """" _
& ", """ & strFolder & """" _
& ", """ & strTemp & """" _
& ", """ & strSize & """" _
& ", """ & dateMod & """" _
& ", """ & dateDD & """" _
& ", """ & dateMM & """" _
& ", """ & dateYY & """" _
& ", """ & strCamera & ");"
DoCmd.SetWarnings (warningson)
DoCmd.RunSQL strSQL
'colDirList.Add strFolder & strTemp
strTemp = Dir
Loop
If bIncludeSubfolders Then
'Build collection of additional subfolders.
strTemp = Dir(strFolder, vbDirectory)
Do While strTemp <> vbNullString
If (strTemp <> ".") And (strTemp <> "..") Then
If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0& Then
colFolders.Add strTemp
End If
End If
strTemp = Dir
Loop
'Call function recursively for each subfolder.
For Each vFolderName In colFolders
Call FillDirToTable(colDirList, strFolder & TrailingSlash(vFolderName), strFileSpec, True)
Next vFolderName
End If
Exit_Handler:
strMsg = strFunction & "Sucessful exit."
Call CStatus(strMsg, 218)
Exit Function
Err_Handler:
'Error Handling
Exit Function
err_hand:
strErrMsg = strFunction & "> " & Err.Number & " " & Err.Source & " " & Err.description
Call CStatus(strErrMsg, 518, Err.Number, Err.description, Err.Source)
strSQL = "INSERT INTO Files " _
& " (FName, FPath) " _
& " SELECT "" ~~~ ERROR ~~~""" _
& ", """ & strFolder & """;"
CurrentDb.Execute strSQL
Resume Exit_Handler
End Function