Option Compare Database
Option Explicit
'Using the FSO requires setting a reference to "Microsoft Scripting Runtime".
'Module-Level Variables/Constants
Private fso As Scripting.FileSystemObject
'Change the following constants to the appropriate folder names
Const cstrXLSpath As String = "\\Murph\home$\saunderp\border"
'This sub gets the whole process started...
Sub UpdateMsdsHyperlinks()
Dim FolderXLS As Scripting.Folder
Dim errorMes As Variant
'On Error GoTo Link_Error
DoCmd.SetWarnings False
DoCmd.OpenQuery ("qryDelXLFiles")
DoCmd.SetWarnings True
Set fso = CreateObject("Scripting.FileSystemObject")
Set FolderXLS = fso.GetFolder(cstrXLSpath)
funFindXLS FolderXLS
Links_Exit:
Exit Sub
Link_Error: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 3109 ' no permision to delete records.
GoTo Links_Exit
Case Else
errorMes = MsgBox("Error Number " & Err.Number, vbCritical, "Code Error")
GoTo Links_Exit
End Select
End Sub
'This sub does all the work
Private Sub funFindXLS(FolderXLS As Scripting.Folder)
Dim SubFolderXLS As Scripting.Folder
Dim oFile As Scripting.File
Dim strFile As String
Dim dbs As Database
Dim rstXLS As Recordset
Set dbs = CurrentDb
Set rstXLS = dbs.OpenRecordset("tblXLfiles")
With rstXLS
'For each subfolder in the main folder, run this sub recursively
If FolderXLS.SubFolders.Count Then
For Each SubFolderXLS In FolderXLS.SubFolders
funFindXLS SubFolderXLS
Next 'SubFolderXLS
End If
'scan each file in the folder and to see if it is an XLS
For Each oFile In FolderXLS.Files
strFile = UCase$(oFile.Name)
If Right(strFile, 3) = "XLS" Then
'add file here
.AddNew
!filepath = oFile.Path
.Update
End If
Next 'oFile
.Close
End With
Set rstXLS = Nothing
Set dbs = Nothing
End Sub