Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub DirTest()
Dim strFolderName As String
'----------------------------------------------
'- The first time you call Dir$, you pass it -
'- the folder name, and file type if required -
'----------------------------------------------
strFolderName = Dir$("s:\*.mdb")
debug.print strFolderName
'----------------------------------------------
'- Now you execute a loop, calling Dir$ again -
'- with no parameters. This will return file -
'- names until all have been found, then -
'- returns "" - blank string -
'----------------------------------------------
Do
strFolderName = Dir$
debug.print strFolderName
Loop Until strFolderName = ""
End Sub
dim strSQL as string
strSQL = "INSERT INTO tblTableName (Filename) "
strSQL = strSQL & "VALUES (" & strFileName & ")"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)
Sub GetFileNames()
Dim strFolderName As String
strFolderName = Dir$("s:\*.mdb")
SaveFileName(strFolderName)
Do
strFolderName = Dir$
SaveFileName(strFolderName)
Loop Until strFolderName = ""
End Sub
Function SaveFileName(strFileName as string)
dim strSQL as string
if strFileName = "" then
exit function
end if
strSQL = "INSERT INTO tblFileNames (Filename) "
strSQL = strSQL & "VALUES (" & strFileName & ")"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)
End Function
DoCmd.SetWarnings (False)
'DoCmd.RunSQL (strSQL)
msgbox strSQL
debug.print strSQL
DoCmd.SetWarnings (True)
strSQL = "INSERT INTO tblFileNames (Filename) "
strSQL = strSQL & "VALUES ('" & strFileName & "')"
msgbox FileDateTime("S:\" & strFileName)
Function SaveFileDetails(strFilePath as string, strFileName as string)
'Pass the path to the file, as well as the
'file name, to this function
dim strFileDate as string
dim strSQL as string
if strFileName = "" then
exit function
end if
'Get the file date and time
strFileDate = FileDateTime(strFilePath & strFileName)
'Format the date as required for your table
strFileDate = Format$(strFileDate, "dd/mm/yyyy")
strSQL = "INSERT INTO tblFileNames (Filename, Filedate) "
strSQL = strSQL & " VALUES ('" & strFileName & "', '"
strSQL = strSQL & strFileDate & "')"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)
End Function
Option Explicit
Public Function AppendFileList(strFolder As String, IncludeSubFolders As Boolean)
On Error GoTo errHandler
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFiles As File
Dim strFileNames As String
Dim strSubFolder As Folder
Dim strCount As String
Dim strFilesFound As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
For Each objFiles In objFolder.Files
DoCmd.SetWarnings False
strCount = strCount + 1
DoCmd.RunSQL ("Insert Into BatchImport Values('" & objFiles.Name & "','" & objFolder.Path & "';")
DoCmd.SetWarnings True
DoEvents
strFilesFound = strFilesFound & vbCrLf & objFiles.Name
Next
If IncludeSubFolders = True Then
For Each strSubFolder In objFolder.SubFolders
Call AppendFileList(strSubFolder.Path, True)
Next
End If
errHandler:
If Err.Number > 0 Then
If MsgBox("Encountered following error." & vbCrLf & vbCrLf & Err.Number & "-" & Err.Description & vbCrLf & vbCrLf & "Do you want to exit?", vbYesNo + vbExclamation, "Error") = vbYes Then
End
Else
Resume Next
End If
End If
End Function