I found this code but am unsure where to put it or how to run it...
A bit longwinded but here is the code taht finds all the files on your c drive
1. First set up a table called "tbl_FilesInFolders"
Filelds FileInFolderID = AutoNumber FolderName = Text 255 FileName = Text 255
Copy and Run the following code
Option Compare Database Option Explicit
Public Function fFileinFolder() As Long On Error Resume Next
Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim intStart As Integer Dim lngFiles As Long Dim lngFilesCount As Long Dim strFile As String Dim strDir As String Dim strDirFile As String Dim strSQL As String Dim fs As Object Dim rstDetail As Object Dim lngTotalErrors As Long Dim strFolder As String Dim strFoundInFolder As String On Error GoTo FileinFolder_Error lngTotalErrors = 0 strFolder = "C:\" '-- Delete Contents of Existing Table DoCmd.RunSQL ("DELETE * FROM tbl_FilesInFolders;")
'-- Trap directory not found If Dir(strFolder, vbDirectory) = "" Then MsgBox "Directory Not Found:" & vbCrLf & strFolder, vbCritical, "Audit File List" GoTo FileinFolder_Exit End If '-- Set up files used Set dbs = CurrentDb Set fs = Application.FileSearch Set rstDetail = dbs.OpenRecordset("tbl_FilesInFolders", dbOpenDynaset) '-- Look into Folders With fs .lookin = strFolder .SearchSubFolders = True .FileName = "*.*" 'search for all file 'if just say excel then .FileName = "*.XLS" If .Execute() > 0 Then DoCmd.Hourglass True lngFilesCount = .foundfiles.Count '-- Get Data in a loop For lngFiles = 1 To lngFilesCount On Error Resume Next '-- Full path & file name strDirFile = .foundfiles(lngFiles) '-- Get file & dir names intStart = LastInStr(strDirFile, "\") strFoundInFolder = Left(strDirFile, intStart) strFile = Mid$(strDirFile, intStart + 1) '-- Write data to file rstDetail.AddNew rstDetail!FolderName = strFoundInFolder rstDetail!FileName = strFile rstDetail.Update Next lngFiles Else MsgBox "No files were found in the directory.", vbInformation, "File List" End If End With
FileinFolder_Exit: On Error Resume Next rst.Close rstDetail.colse Set dbs = Nothing Exit Function FileinFolder_Error: MsgBox Err.Description, vbCritical, "File List Error" Resume FileinFolder_Exit
End Function Function LastInStr(strSearched As String, strSought As String) As Integer Dim intCurrVal As Integer, intLastPosition As Integer intCurrVal = InStr(strSearched, strSought) Do Until intCurrVal = 0 intLastPosition = intCurrVal intCurrVal = InStr(intLastPosition + 1, strSearched, strSought) Loop LastInStr = intLastPosition
End Function
"Daniel Pineault" wrote:
[Quoted Text] > Use the FollowHyperlink Method > > Application.FollowHyperlink "FullPath" > > So if on your form your have a control named ProjCode which should > correspond to the directory your are interested in, you could do something > like > > Dim sBasePath as String > sBasePath = "\\ServerName\projects\" > > Application.FollowHyperlink sBasePath & Me.ProjCode & "\" > -- > Hope this helps, > > Daniel Pineault > http://www.cardaconsultants.com/> For Access Tips and Examples: http://www.devhut.net> Please rate this post using the vote buttons if it was helpful. > > > > "Erin Freeman" wrote: > > > Hi there, > > > > I have a database that we track projects with. On our server we have a > > specific location for each project (by project code) Is there any way to have > > a button on the form that when clicked would either show you the directory > > (somewhat like the search function) or would open up a new windows explorer > > and go to that directory? > > > > Thank you in advance for taking the time to answer this post.
|